Chilkat Online Tools

C / DocuSign REST API / 1. Create an Envelope

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

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"documents[0].documentBase64","{{documentBase64}}");
    CkJsonObject_UpdateInt(json,"documents[0].documentId",123);
    CkJsonObject_UpdateString(json,"documents[0].fileExtension","pdf");
    CkJsonObject_UpdateString(json,"documents[0].name","document");
    CkJsonObject_UpdateString(json,"emailSubject","Simple Signing Example");
    CkJsonObject_UpdateString(json,"recipients.signers[0].email","{{email}}");
    CkJsonObject_UpdateString(json,"recipients.signers[0].name","{{name}}");
    CkJsonObject_UpdateString(json,"recipients.signers[0].recipientId","{{recipientId}}");
    CkJsonObject_UpdateString(json,"status","sent");

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

    resp = CkHttp_PostJson3(http,"https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes","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 "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_email}},
        "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_email}},\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": [
  ]
}