Chilkat Online Tools

PowerBuilder / DocuSign REST API / 15. Create an Account Template

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": [
//     {
//       "name": "agreement",
//       "documentBase64": "{{documentBase64}}",
//       "documentId": 123,
//       "fileExtension": "pdf"
//     }
//   ],
//   "emailBlurb": "Email message",
//   "emailSubject": "email subject",
//   "recipients": {
//     "signers": [
//       {
//         "recipientId": "1",
//         "roleName": "seller",
//         "email": "{{email}}",
//         "name": "{{name}}",
//         "tabs": {
//           "signHereTabs": [
//             {
//               "documentId": "123",
//               "pageNumber": 1,
//               "xPosition": "4",
//               "yPosition": "4"
//             }
//           ]
//         }
//       }
//     ]
//   }
// }

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].name","agreement")
loo_Json.UpdateString("documents[0].documentBase64","{{documentBase64}}")
loo_Json.UpdateInt("documents[0].documentId",123)
loo_Json.UpdateString("documents[0].fileExtension","pdf")
loo_Json.UpdateString("emailBlurb","Email message")
loo_Json.UpdateString("emailSubject","email subject")
loo_Json.UpdateString("recipients.signers[0].recipientId","1")
loo_Json.UpdateString("recipients.signers[0].roleName","seller")
loo_Json.UpdateString("recipients.signers[0].email","{{email}}")
loo_Json.UpdateString("recipients.signers[0].name","{{name}}")
loo_Json.UpdateString("recipients.signers[0].tabs.signHereTabs[0].documentId","123")
loo_Json.UpdateInt("recipients.signers[0].tabs.signHereTabs[0].pageNumber",1)
loo_Json.UpdateString("recipients.signers[0].tabs.signHereTabs[0].xPosition","4")
loo_Json.UpdateString("recipients.signers[0].tabs.signHereTabs[0].yPosition","4")

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}}/templates","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": [
    {
      "name": "agreement",
      "documentBase64": {{document}},
      "documentId": {{documentId}},
      "fileExtension": "pdf"
    }
  ],
  "emailBlurb": "Email message",
  "emailSubject": "email subject",
  "recipients": {
    "signers": [
      {
        "recipientId": "1",
        "roleName": "seller",
        "email":{{user1_email}},
        "name": {{user1_name}},
        "tabs": {
          "signHereTabs": [
            {
              "documentId": "123",
              "pageNumber": 1,
              "xPosition": "4",
              "yPosition": "4"
            }
          ]
        }
      }
    ]
  }
}'
https://domain.com/{{apiVersion}}/accounts/{{accountId}}/templates

Postman Collection Item JSON

{
  "name": "15. Create an Account Template",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"templateId\", jsonData.templateId);"
        ]
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{accessToken}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"documents\": [\n    {\n      \"name\": \"agreement\",\n      \"documentBase64\": {{document}},\n      \"documentId\": {{documentId}},\n      \"fileExtension\": \"pdf\"\n    }\n  ],\n  \"emailBlurb\": \"Email message\",\n  \"emailSubject\": \"email subject\",\n  \"recipients\": {\n    \"signers\": [\n      {\n        \"recipientId\": \"1\",\n        \"roleName\": \"seller\",\n        \"email\":{{user1_email}},\n        \"name\": {{user1_name}},\n        \"tabs\": {\n          \"signHereTabs\": [\n            {\n              \"documentId\": \"123\",\n              \"pageNumber\": 1,\n              \"xPosition\": \"4\",\n              \"yPosition\": \"4\"\n            }\n          ]\n        }\n      }\n    ]\n  }\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/{{apiVersion}}/accounts/{{accountId}}/templates",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "{{apiVersion}}",
        "accounts",
        "{{accountId}}",
        "templates"
      ]
    },
    "description": "In this example, we will create a template with document, tabs and its recipients specified. This is a great future if we know we will be sending the same envelope multiple times."
  },
  "response": [
  ]
}