How to request a signature through your CORS-enabled browser app
This topic demonstrates how to collect signatures directly within your browser app using JavaScript, without emailing the signer or directing them to an external URL,
through your Cross-Origin Resource Sharing (CORS) app within your developer account.
CORS is a technology standard that allows restricted resources such as scripts, forms, or external web pages to be requested from a domain that’s different from the server originating the request. Access to each resource requested via CORS is controlled by CORS access policies set on the server hosting that resource.
CORS enables you to build browser-based applications that can directly call the Docusign eSignature REST API. Your app can use React, Vue, or other browser-based frameworks, or just JavaScript. With CORS, no back-end server is needed.
Prerequisites
To send CORS requests:
-
Since the sender needs Docusign credentials to call the eSignature REST API, the sender needs their own login to the Docusign service. If the sender will also be signing the envelope, or if the signer is physically present with the sender, then this example is applicable.
If the signer does not have a Docusign login, then a back-end service (using JWT authentication) should create an access token and use it to call the eSignature REST API.
-
The system administrator for the application’s integration key (client ID) must enable the application to use CORS from the origin(s) the application will be loaded from. For example, if the application’s URL is
https://apps.mycompany.com/docusign, the originhttps://apps.mycompany.commust be enabled for CORS. See Enable or disable CORS for specific apps for details. -
The account administrator for every user of your application must also enable CORS access by your application. While the default is to enable CORS access, your users’ administrators can change the default. For instance, suppose your application has 20 users scattered across four companies and five individual eSignature accounts (one of the companies has multiple accounts). In this scenario, five different account administrators must enable CORS access by your application or leave the default setting to CORS enabled by default for all new apps. See Requirements for an app to use CORS for details.
Required data
Running the code in this how-to requires this data:
Step 1. Obtain your OAuth token
To make the API calls shown in this how-to, you need a valid OAuth access token.
CORS-enabled apps should use OAuth Authorization Code Grant, without a secret, with Proof Key for Code Exchange (PKCE) to obtain an access token. A special cors scope is required along with signature when generating your OAuth token request.
Step 2. Construct the request body
Construct the request body by defining a method named createEnvelope that creates the envelope definition. The createEnvelope method demonstrates how to:
- Create a new, signable PDF document in code
- Attach your document to the envelope
- Set signer data
- Create and assign a
SignHeretab to the signer
Define the createEnvelope method with this code.
Step 3. Call the eSignature REST API to create the envelope
Now that you have constructed your API headers and request body, you can
make a POST request to the Envelopes:create method and include the request body to send
an embedded envelope using CORS.
Here’s how you make the call, but make sure to substitute your API account ID for {ACCOUNT_ID}
. Save the envelope ID to use in the next step.
Step 4. Call the eSignature REST API to initiate the embedded signing request
Next, create the recipient view. Use the EnvelopeViews:createRecipient method, passing in your API account ID and the envelopeId and viewRequest objects generated in previous steps.
Finally, extract the URL for embedded signing, which is the value of the Url key from the JSON response. You can redirect your app’s internal browser to this URL to begin signing.
Expected response
You should see a JSON response similar to the code shown.
After signing is complete, the recipient receives a carbon copy (CC) of the email that includes all of the completed and signed documents.