Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) DocuSign Add One Document to a Draft EnvelopeSee more DocuSign ExamplesDemonstrates how to add one document to a DocuSign draft envelope. For more information, see https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopedocuments/updatelist/
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkBinDataW.h> #include <C_CkStringBuilderW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkJsonObjectW jsonToken; BOOL success; HCkBinDataW bd1; HCkJsonObjectW json; HCkStringBuilderW sbJson; const wchar_t *url; HCkHttpResponseW resp; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *documentId; const wchar_t *documentIdGuid; const wchar_t *name; const wchar_t *v_type; const wchar_t *uri; const wchar_t *order; const wchar_t *containsPdfFormFields; const wchar_t *templateRequired; const wchar_t *authoritativeCopy; const wchar_t *envelopeId; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // Load a previously obtained OAuth2 access token. jsonToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/docusign.json"); if (success == FALSE) { wprintf(L"%s\n",CkJsonObjectW_lastErrorText(jsonToken)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); return; } // Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header. CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token")); // Send the following request. // Make sure to use your own account ID (obtained from Get Docusign User Account Information) // PUT https://demo.docusign.net/restapi/v2.1/accounts/<account ID>/envelopes/<envelope ID>/documents HTTP/1.1 // Expect: 100-continue // Accept: application/json // Cache-Control: no-cache // Authorization: Bearer eyJ0eX... // Content-Length: ... // Content-Type: application/json // // { // "documents": [ // { // "documentId": "1", // "name": "project_xyz.pdf", // "pages": "1", // "documentBase64": "<insert base64 content here>" // } // ] // } bd1 = CkBinDataW_Create(); success = CkBinDataW_LoadFile(bd1,L"qa_data/pdf/project_xyz.pdf"); json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"documents[0].documentId",L"1"); CkJsonObjectW_UpdateString(json,L"documents[0].name",L"project_xyz.pdf"); CkJsonObjectW_UpdateString(json,L"documents[0].pages",L"1"); CkJsonObjectW_UpdateString(json,L"documents[0].documentBase64",CkBinDataW_getEncoded(bd1,L"base64")); sbJson = CkStringBuilderW_Create(); CkJsonObjectW_putEmitCompact(json,FALSE); CkJsonObjectW_EmitSb(json,sbJson); CkHttpW_SetRequestHeader(http,L"Expect",L"100-continue"); CkHttpW_SetRequestHeader(http,L"Cache-Control",L"no-cache"); CkHttpW_SetRequestHeader(http,L"Accept",L"application/json"); // Use your own account ID here. CkHttpW_SetUrlVar(http,L"accountId",L"7f3f65ed-5e87-418d-94c1-92499ddc8252"); // Use the envelope ID returned by DocuSign when creating the draft envelope). CkHttpW_SetUrlVar(http,L"envelopeId",L"0b437b95-cc50-475f-8dec-65bae9f27d09"); url = L"https://demo.docusign.net/restapi/v2.1/accounts/{$accountId}/envelopes/{$envelopeId}/documents"; resp = CkHttpW_PTextSb(http,L"PUT",url,sbJson,L"utf-8",L"application/json",FALSE,FALSE); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkBinDataW_Dispose(bd1); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbJson); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_Load(jResp,CkHttpResponseW_bodyStr(resp)); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); // If you get a 401 response status code, it's likely you need to refresh the DocuSign OAuth2 token). respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkBinDataW_Dispose(bd1); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbJson); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_Dispose(resp); // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "envelopeId": "da9fb811-e6a4-48c0-a9fb-81ed18b989af", // "envelopeDocuments": [ // { // "documentId": "1", // "documentIdGuid": "38e919fc-0a77-4b0c-9da0-e3530f4e6fc7", // "name": "project_xyz.pdf", // "type": "content", // "uri": "/envelopes/da9fb811-e6a4-48c0-a9fb-81ed18b989af/documents/1", // "order": "3", // "containsPdfFormFields": "false", // "templateRequired": "false", // "authoritativeCopy": "false" // } // ] // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON envelopeId = CkJsonObjectW_stringOf(jResp,L"envelopeId"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"envelopeDocuments"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); documentId = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].documentId"); documentIdGuid = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].documentIdGuid"); name = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].name"); v_type = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].type"); uri = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].uri"); order = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].order"); containsPdfFormFields = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].containsPdfFormFields"); templateRequired = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].templateRequired"); authoritativeCopy = CkJsonObjectW_stringOf(jResp,L"envelopeDocuments[i].authoritativeCopy"); i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkBinDataW_Dispose(bd1); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbJson); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.