How to request a signature using a composite template
This topic demonstrates how to request a signature through your app using a template and an additional, dynamically-constructed HTML document by using the composite template feature.
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 as a part of the composite template
First, create a new envelope definition that declares a pair of compositeTemplate objects. Each of these objects will represent one template that you will use to derive the created envelope. The first of these composite templates will be derived from one of your existing templates, specified by its template ID. It is divided into a serverTemplate (which holds server-side template data, such as ordering) and an inlineTemplate (which holds inline template data, such as tabs/fields). The second composite template will contain the HTML document, as well as its tabs and recipients.
Note: When you create an envelope by using a composite template, you should specify the envelope custom fields in the inline template. Any custom fields that you specify at the root level are ignored.
The code for this step demonstrates how to define a method, makeEnvelope, that creates an envelope definition using composite templates:
Step 3. Call Docusign to create the envelope
Next, create the envelope from the definition that you created in the previous step, then create the recipient view for embedded signing.
- Instantiate the Docusign API client.
- Set the following default request header to add your access token.
"Authorization" : "Bearer {ACCESS_TOKEN}"
3. Initialize the Envelopes API.
4. Create an envelope by passing in the generated envelope definition and your API account ID.
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. The recipient view request returns a link that enables your recipients to sign documents from your app. To create the definition, you must add the signer’s information and the redirect URI.
-
Set the redirect URI to which the user will be forwarded after signing is complete. This URI must exactly match one that is preregistered for the integration key in your Docusign account.
Note: You can include a
stateparameter in the URI string to record your application’s state and provide recovery information, potentially enabling it to resume interrupted operations using only callback data. -
Add the recipient information to the view, including the signer’s email, name, and client user ID.
Expected response
If you run this code example from our Quickstart or launcher projects, you should see a JSON response similar to the code shown.
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 templates or composite templates.
- See how to Go-Live with a completed app and find the base path for API calls in the production environment.