Skip to content

anamartinsr/docusign-integration

Repository files navigation

Api DocuSend

DocuSign Integration

Backend API that integrates with the DocuSign eSignature API to create envelopes and generate embedded signing URLs for recipients.

Overview

This application exposes endpoints used by a frontend form/signing flow.

Data Flow

Main workflow:

  1. A user fills out a form in the frontend.
  2. The backend creates a DocuSign envelope.
  3. The backend generates an embedded signing URL for the recipient.
  4. The frontend receives that URL and redirects the user to the DocuSign signing page.

The signing process uses embedded signing via a generated recipient view URL.

Architecture

This backend follows Clean Architecture to keep responsibilities separated and code easier to maintain. In short: Presentation handles HTTP, Application runs use cases, Domain defines contracts, and Infrastructure integrates with DocuSign and external services.

API Endpoints

POST /form

Creates a new DocuSign envelope based on submitted form data.

Behavior:

  • Requires authenticated DocuSign context via middleware.
  • Returns the created envelopeId as JSON.

GET /assinatura/:envelopeId/:email/:name/:role

Generates an embedded signing URL for the specified recipient.

Path parameters:

  • envelopeId: DocuSign envelope identifier.
  • email: recipient email.
  • name: recipient full name.
  • role: currently expected as signer.

Behavior:

  • Backend validates role.
  • Backend returns JSON with signing URL (no HTTP redirect):
{
	"signingUrl": "https://..."
}

Note:

  • The project also keeps a compatibility route: GET /signature/:envelopeId/:email/:name/:role.

Environment Variables

This codebase currently reads the following variables:

Variable Required Description
APP_PORT Yes Port where the backend runs (example: 3000).
BASE_PATH Yes DocuSign REST base path (example: https://demo.docusign.net/restapi).
INTEGRATION_KEY Yes DocuSign Integration Key (client ID).
USER_ID Yes DocuSign user GUID used for JWT impersonation.
ACCOUNT_ID Yes DocuSign account GUID used in API requests.
CLIENT_USER_ID Yes Embedded signing client user ID for recipient view.
TEMPLATE_ID Yes DocuSign template ID used for envelope creation.
ORIGIN Yes Allowed frontend origin for CORS and signing return URL fallback.
RETURN_URL Yes Frontend URL used after embedded signing is completed.
SESSION_SECRET Yes Secret used by express-session.

DocuSign Authorization Setup

Before running the project, grant consent for the integration key/user in your DocuSign developer environment.

Open this URL in your browser and replace placeholders:

https://account-d.docusign.com/oauth/auth?response_type=code&scope=signature%20impersonation&client_id=(YOUR%20INTEGRATION%20KEY)&redirect_uri=http://localhost:3000/

Steps:

  1. Replace (YOUR INTEGRATION KEY) with your DocuSign Integration Key.
  2. Replace the redirect_uri if your app runs on a different URL.
  3. Open the URL in your browser.
  4. Sign in with your DocuSign developer account.
  5. Grant permission to the application.
  6. After authorization, DocuSign redirects with an authorization code in the URL.

This consent step allows the backend to interact with the DocuSign API on behalf of the configured user.

Installation

  1. Clone the repository.
  2. Enter the project folder.
  3. Install dependencies.
  4. Create and configure .env.
  5. Place private.key in the project root.
  6. Authorize the DocuSign integration (consent step above).
  7. Start the server.

Example:

git clone <repository-url>
cd docusign-integration
npm install
npm run dev

Technologies Used

  • Node.js
  • Express
  • TypeScript
  • Jest
  • Clean Architecture principles
  • DocuSign eSignature API

About

Backend API that integrates with the DocuSign eSignature API using Node.js, TypeScript, Jest

Resources

Stars

Watchers

Forks

Contributors