Chilkat Online Tools

C / DocuSign eSignature REST API / 15. Create an Account Template

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkHttpResponse resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttp_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",
    //         "email": "{{email}}",
    //         "name": "{{name}}",
    //         "tabs": {
    //           "signHereTabs": [
    //             {
    //               "documentId": "123",
    //               "pageNumber": 1,
    //               "xPosition": "4",
    //               "yPosition": "4"
    //             }
    //           ]
    //         }
    //       }
    //     ]
    //   }
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"documents[0].name","agreement");
    CkJsonObject_UpdateString(json,"documents[0].documentBase64","{{documentBase64}}");
    CkJsonObject_UpdateInt(json,"documents[0].documentId",123);
    CkJsonObject_UpdateString(json,"documents[0].fileExtension","pdf");
    CkJsonObject_UpdateString(json,"emailBlurb","Email message");
    CkJsonObject_UpdateString(json,"emailSubject","email subject");
    CkJsonObject_UpdateString(json,"recipients.signers[0].recipientId","1");
    CkJsonObject_UpdateString(json,"recipients.signers[0].email","{{email}}");
    CkJsonObject_UpdateString(json,"recipients.signers[0].name","{{name}}");
    CkJsonObject_UpdateString(json,"recipients.signers[0].tabs.signHereTabs[0].documentId","123");
    CkJsonObject_UpdateInt(json,"recipients.signers[0].tabs.signHereTabs[0].pageNumber",1);
    CkJsonObject_UpdateString(json,"recipients.signers[0].tabs.signHereTabs[0].xPosition","4");
    CkJsonObject_UpdateString(json,"recipients.signers[0].tabs.signHereTabs[0].yPosition","4");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttp_putAuthToken(http,"<access_token>");

    resp = CkHttp_PostJson3(http,"https://domain.com/{{apiVersion}}/accounts/{{accountId}}/templates","application/json",json);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
  "documents": [
    {
      "name": "agreement",
      "documentBase64": {{document}},
      "documentId": {{documentId}},
      "fileExtension": "pdf"
    }
  ],
  "emailBlurb": "Email message",
  "emailSubject": "email subject",
  "recipients": {
    "signers": [
      {
        "recipientId": "1",
        "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": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "var templateId = jsonData.templateId;",
          "postman.setEnvironmentVariable(\"templateId\", templateId); "
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{accessToken}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "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        \"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}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "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": [
  ]
}