unicodeC / DocuSign Click API / 15. Create an Account Template
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// 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",
// "email": "{{email}}",
// "name": "{{name}}",
// "tabs": {
// "signHereTabs": [
// {
// "documentId": "123",
// "pageNumber": 1,
// "xPosition": "4",
// "yPosition": "4"
// }
// ]
// }
// }
// ]
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"documents[0].name",L"agreement");
CkJsonObjectW_UpdateString(json,L"documents[0].documentBase64",L"{{documentBase64}}");
CkJsonObjectW_UpdateInt(json,L"documents[0].documentId",123);
CkJsonObjectW_UpdateString(json,L"documents[0].fileExtension",L"pdf");
CkJsonObjectW_UpdateString(json,L"emailBlurb",L"Email message");
CkJsonObjectW_UpdateString(json,L"emailSubject",L"email subject");
CkJsonObjectW_UpdateString(json,L"recipients.signers[0].recipientId",L"1");
CkJsonObjectW_UpdateString(json,L"recipients.signers[0].roleName",L"seller");
CkJsonObjectW_UpdateString(json,L"recipients.signers[0].email",L"{{email}}");
CkJsonObjectW_UpdateString(json,L"recipients.signers[0].name",L"{{name}}");
CkJsonObjectW_UpdateString(json,L"recipients.signers[0].tabs.signHereTabs[0].documentId",L"123");
CkJsonObjectW_UpdateInt(json,L"recipients.signers[0].tabs.signHereTabs[0].pageNumber",1);
CkJsonObjectW_UpdateString(json,L"recipients.signers[0].tabs.signHereTabs[0].xPosition",L"4");
CkJsonObjectW_UpdateString(json,L"recipients.signers[0].tabs.signHereTabs[0].yPosition",L"4");
// Adds the "Authorization: Bearer {{accessToken}}" header.
CkHttpW_putAuthToken(http,L"{{accessToken}}");
resp = CkHttpW_PostJson3(http,L"https://domain.com/{{apiVersion}}/accounts/{{accountId}}/templates",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
}
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",
"email":{{user1}},
"name": {{user1_name}},
"tabs": {
"signHereTabs": [
{
"documentId": "123",
"pageNumber": 1,
"xPosition": "4",
"yPosition": "4"
}
]
}
}
]
}
}'
https://domain.com/{{apiVersion}}/accounts/{{accountId}}/templates
Postman Collection Item JSON
{
"name": "15. Create an Account Template",
"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 \"email\":{{user1}},\n \"name\": {{user1_name}},\n \"tabs\": {\n \"signHereTabs\": [\n {\n \"documentId\": \"123\",\n \"pageNumber\": 1,\n \"xPosition\": \"4\",\n \"yPosition\": \"4\"\n }\n ]\n }\n }\n ]\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/{{apiVersion}}/accounts/{{accountId}}/templates",
"host": [
"{{baseUrl}}"
],
"path": [
"{{apiVersion}}",
"accounts",
"{{accountId}}",
"templates"
]
},
"description": "In this example, we will create a template with document, tabs and its recipients specified. This is a great future if we know we will be sending the same envelope multiple times."
},
"response": [
]
}