PowerBuilder / DocuSign REST API / 2. Create Envelope in Draft Stage
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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"
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("documents[0].documentBase64","{{documentBase64}}")
loo_Json.UpdateString("documents[0].documentId","123")
loo_Json.UpdateString("documents[0].fileExtension","pdf")
loo_Json.UpdateString("documents[0].name","document")
loo_Json.UpdateString("emailSubject","Simple Signing Example")
loo_Json.UpdateString("recipients.signers[0].email","{{email}}")
loo_Json.UpdateString("recipients.signers[0].name","{{name}}")
loo_Json.UpdateString("recipients.signers[0].recipientId","{{recipientId}}")
loo_Json.UpdateString("status","created")
loo_Http.SetRequestHeader("Content-Type","application/json")
// Adds the "Authorization: Bearer {{accessToken}}" header.
loo_Http.AuthToken = "{{accessToken}}"
loo_Resp = loo_Http.PostJson3("https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_Json
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_email}},
"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_email}},\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": [
]
}