DataFlex / DocuSign Click API / 2. Create Envelope in Draft Stage
Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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": "created"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "documents[0].documentBase64" "{{documentBase64}}" To iSuccess
Get ComUpdateString Of hoJson "documents[0].documentId" "123" To iSuccess
Get ComUpdateString Of hoJson "documents[0].fileExtension" "pdf" To iSuccess
Get ComUpdateString Of hoJson "documents[0].name" "document" To iSuccess
Get ComUpdateString Of hoJson "emailSubject" "Simple Signing Example" To iSuccess
Get ComUpdateString Of hoJson "recipients.signers[0].email" "{{email}}" To iSuccess
Get ComUpdateString Of hoJson "recipients.signers[0].name" "{{name}}" To iSuccess
Get ComUpdateString Of hoJson "recipients.signers[0].recipientId" "{{recipientId}}" To iSuccess
Get ComUpdateString Of hoJson "status" "created" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
// Adds the "Authorization: Bearer {{accessToken}}" header.
Set ComAuthToken Of hoHttp To "{{accessToken}}"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Send Destroy of hoResp
End_Procedure
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Authorization: Bearer {{accessToken}}"
-d '{
"documents": [
{
"documentBase64": {{document}},
"documentId": "123",
"fileExtension": "pdf",
"name": "document"
}
],
"emailSubject": "Simple Signing Example",
"recipients": {
"signers": [
{
"email": {{user1}},
"name": {{user1_name}},
"recipientId": "{{recipientId}}"
}
]
},
"status": "created"
}'
https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes
Postman Collection Item JSON
{
"name": "2. Create Envelope in Draft Stage",
"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\": \"123\",\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\": \"created\"\n}"
},
"url": {
"raw": "{{baseUrl}}/{{apiVersion}}/accounts/{{accountId}}/envelopes",
"host": [
"{{baseUrl}}"
],
"path": [
"{{apiVersion}}",
"accounts",
"{{accountId}}",
"envelopes"
]
},
"description": "In this example, we are creating an envelope similar to the previous step. However, we are keeping it in `draft` stage so can continue to make changes to it. If the status was set to `sent` the envelope would be sent to users."
},
"response": [
]
}