Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// 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"
// }
let json = CkoJsonObject()!
json.update("documents[0].documentBase64", value: "{{documentBase64}}")
json.update("documents[0].documentId", value: "123")
json.update("documents[0].fileExtension", value: "pdf")
json.update("documents[0].name", value: "document")
json.update("emailSubject", value: "Simple Signing Example")
json.update("recipients.signers[0].email", value: "{{email}}")
json.update("recipients.signers[0].name", value: "{{name}}")
json.update("recipients.signers[0].recipientId", value: "{{recipientId}}")
json.update("status", value: "created")
// Adds the "Authorization: Bearer <access_token>" header.
http.authToken = "<access_token>"
http.setRequestHeader("Content-Type", value: "application/json")
var resp: CkoHttpResponse? = http.postJson3("https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes", contentType: "application/json", json: json)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("\(resp!.statusCode.intValue)")
print("\(resp!.bodyStr!)")
resp = nil
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-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",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);",
"var envelopeId = jsonData.envelopeId;",
"postman.setEnvironmentVariable(\"envelopeId_draft\", envelopeId); ",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{accessToken}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"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're 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": [
]
}