Node.js / DocuSign Click API / 19. Create a Template with Role Only
Back to Collection Items
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node21-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node21-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node21-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node21-linux32');
} else {
var chilkat = require('@chilkat/ck-node21-linux64');
}
} else if (os.platform() == 'darwin') {
if (os.arch() == 'arm64') {
var chilkat = require('@chilkat/ck-node21-mac-m1');
} else {
var chilkat = require('@chilkat/ck-node21-macosx');
}
}
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
var success;
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "documents": [
// {
// "name": "agreement",
// "documentBase64": "{{documentBase64}}",
// "documentId": 123,
// "fileExtension": "pdf"
// }
// ],
// "emailBlurb": "Email message",
// "emailSubject": "email subject",
// "recipients": {
// "signers": [
// {
// "recipientId": "1",
// "roleName": "seller"
// }
// ]
// }
// }
var json = new chilkat.JsonObject();
json.UpdateString("documents[0].name","agreement");
json.UpdateString("documents[0].documentBase64","{{documentBase64}}");
json.UpdateInt("documents[0].documentId",123);
json.UpdateString("documents[0].fileExtension","pdf");
json.UpdateString("emailBlurb","Email message");
json.UpdateString("emailSubject","email subject");
json.UpdateString("recipients.signers[0].recipientId","1");
json.UpdateString("recipients.signers[0].roleName","seller");
// Adds the "Authorization: Bearer {{accessToken}}" header.
http.AuthToken = "{{accessToken}}";
// resp: HttpResponse
var resp = http.PostJson3("https://domain.com/{{apiVersion}}/accounts/{{accountId}}/templates","application/json",json);
if (http.LastMethodSuccess == false) {
console.log(http.LastErrorText);
return;
}
console.log(resp.StatusCode);
console.log(resp.BodyStr);
}
chilkatExample();
Curl Command
curl -X POST
-H "Authorization: Bearer {{accessToken}}"
-d '{
"documents": [
{
"name": "agreement",
"documentBase64": {{document}},
"documentId": {{documentId}},
"fileExtension": "pdf"
}
],
"emailBlurb": "Email message",
"emailSubject": "email subject",
"recipients": {
"signers": [
{
"recipientId": "1",
"roleName": "seller",
}
]
}
}'
https://domain.com/{{apiVersion}}/accounts/{{accountId}}/templates
Postman Collection Item JSON
{
"name": "19. Create a Template with Role Only",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"templateId\", jsonData.templateId);"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{accessToken}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"documents\": [\n {\n \"name\": \"agreement\",\n \"documentBase64\": {{document}},\n \"documentId\": {{documentId}},\n \"fileExtension\": \"pdf\"\n }\n ],\n \"emailBlurb\": \"Email message\",\n \"emailSubject\": \"email subject\",\n \"recipients\": {\n \"signers\": [\n {\n \"recipientId\": \"1\",\n \"roleName\": \"seller\",\n }\n ]\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/{{apiVersion}}/accounts/{{accountId}}/templates",
"host": [
"{{baseUrl}}"
],
"path": [
"{{apiVersion}}",
"accounts",
"{{accountId}}",
"templates"
]
},
"description": "In order to make templates more board and be able to use them in `CompositeTemplates` we can create them by specifying the role only. This way, the recipients can be specified at envelope creation. This example shows how useful templates can be."
},
"response": [
]
}