How to request a signature through your app
This topic demonstrates how to collect signatures directly within your app, without emailing the signer or directing them to an external URL. This process is called embedded signing. This topic also demonstrates how to use AutoPlace to automatically position tabs in a document with a specified string.
Run this code example from our Quickstart or launcher projects: Bash, C#, Java, Node.js, PHP, PowerShell, Python, or Ruby.
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. Docusign supports access tokens for three different recommended OAuth grant types: Public Authorization Code Grant, Confidential Authorization Code Grant, and JSON Web Token (JWT) Grant. Choose the OAuth grant type appropriate for your scenario.
See Confidential Authorization Code Grant for guidance on your options to get an Confidential Authorization Code Grant OAuth token.
Step 2. Create the envelope definition
The first step in requesting a signature within your app is to define a method (called makeEnvelope in our example) that creates the envelope definition using the following steps:
-
Add a document to the definition by saving it to a variable as a binary-encoded base64 string. If you intend to attach multiple documents, specify the document order using an array. The order of the array sets the order of the documents.
-
Set the signer’s data, including their name, email address, and a client user ID (any alphanumeric value is suitable). Including a client user ID automatically specifies the signer as embedded (using your app). If there are multiple signers, you must create a signer recipient for each one.
Note: If the client user ID is set and either the
SignerMustHaveAccountorSignerMustLoginToSignproperty of the account settings is set totrue, the system throws an error. -
Create and assign signable fields (also known as tabs) for a specific signer within the document using AutoPlace. This how-to uses anchor tabs to generate tabs automatically in your document by searching for each occurrence of a specific string of characters in the document and adding tabs at those locations. This example uses the string “
/sn1/” for auto-placing the signature (signHere) tab.To configure the anchor tabs, specify the number of units from the anchor text to offset the tab, as well as the string to search for and replace with a
signHereTabwithin your document. You can create multiplesignHeretabs for different locations and offsets, if needed.After creating the tabs, assign them to the signer created in the previous step.
-
Set the envelope’s
statusproperty. To save the envelope as a draft, setstatustocreated. To configure the envelope to be sent immediately after it is instantiated, setstatustosentinstead.
Step 3. Call Docusign to create the envelope
With the envelope definition and the attributes defined for the signer, document, and custom fields, you can now use the Envelopes:create endpoint to create an envelope for the transaction.
- First, instantiate a new instance of the API client (if you’re using a Docusign SDK).
- Set the following default request header to add your access token to all API calls.
"Authorization: Bearer ${ACCESS_TOKEN}" - Initialize the Envelopes API.
- Using your Docusign integration key and the prepared envelope definition, generate and retrieve an envelope ID using the Envelopes:create endpoint.
Step 4. Create the recipient view definition
The recipient view is the screen that Docusign generates and displays in your app to enable your signers to sign documents. To create the definition, you must add the signer’s information and the return URL.
- Set the return URL to which the user will be forwarded after signing is complete.
- Add the recipient information to the view, including the signer’s
email,name, andclientUserIDthat were set for the recipient who will sign the envelope.
Step 5. Create the recipient view and initiate embedded signing
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
Use the return URL in the JSON response to start the embedded signing session in your browser.
Next steps
- Run this code example from our Quickstart or launcher projects: Bash, C#, Java, Node.js, PHP, PowerShell, Python, or Ruby.
- Find out more about Embedded signing and sending.
- Learn How to send an envelope via your app.
- See how to Go-Live with a completed app and find the base path for API calls in the production environment.