Chilkat Online Tools

unicodeC / DocuSign Click API / 1. Create an Envelope

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": [
    //     {
    //       "documentBase64": "{{documentBase64}}",
    //       "documentId": 123,
    //       "fileExtension": "pdf",
    //       "name": "document"
    //     }
    //   ],
    //   "emailSubject": "Simple Signing Example",
    //   "recipients": {
    //     "signers": [
    //       {
    //         "email": "{{email}}",
    //         "name": "{{name}}",
    //         "recipientId": "{{recipientId}}"
    //       }
    //     ]
    //   },
    //   "status": "sent"
    // }

    json = CkJsonObjectW_Create();
    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"documents[0].name",L"document");
    CkJsonObjectW_UpdateString(json,L"emailSubject",L"Simple Signing Example");
    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].recipientId",L"{{recipientId}}");
    CkJsonObjectW_UpdateString(json,L"status",L"sent");

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    // Adds the "Authorization: Bearer {{accessToken}}" header.
    CkHttpW_putAuthToken(http,L"{{accessToken}}");

    resp = CkHttpW_PostJson3(http,L"https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes",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 "Content-Type: application/json"
	-H "Authorization: Bearer {{accessToken}}"
	-d '{
  "documents": [
    {
      "documentBase64": {{document}},
      "documentId": {{documentId}},
      "fileExtension": "pdf",
      "name": "document"
    }
  ],
  "emailSubject": "Simple Signing Example",
  "recipients": {
    "signers": [
      {
        "email": {{user1}},
        "name": {{user1_name}},
        "recipientId": "{{recipientId}}"
      }
    ]
  },
  "status": "sent"
}'
https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes

Postman Collection Item JSON

{
  "name": "1. Create an Envelope",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"envelopeId\", jsonData.envelopeId);"
        ]
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{accessToken}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"documents\": [\n    {\n      \"documentBase64\": {{document}},\n      \"documentId\": {{documentId}},\n      \"fileExtension\": \"pdf\",\n      \"name\": \"document\"\n    }\n  ],\n  \"emailSubject\": \"Simple Signing Example\",\n  \"recipients\": {\n    \"signers\": [\n      {\n        \"email\": {{user1}},\n        \"name\": {{user1_name}},\n        \"recipientId\": \"{{recipientId}}\"\n      }\n    ]\n  },\n  \"status\": \"sent\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/{{apiVersion}}/accounts/{{accountId}}/envelopes",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "{{apiVersion}}",
        "accounts",
        "{{accountId}}",
        "envelopes"
      ]
    },
    "description": "This example is a very basic example of creating an evenlope with a document and a single signer. This evenlope does not specify a tab."
  },
  "response": [
  ]
}