Objective-C / DocuSign REST API / 7. Add an Attachment to Envelope
Back to Collection Items
#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.h>
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "attachments": [
// {
// "attachmentId": "123",
// "data": "{{data}}",
// "name": "sample_document",
// "anchorIgnoreIfNotPresent": "false",
// "anchorUnits": "inches"
// }
// ]
// }
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"attachments[0].attachmentId" value: @"123"];
[json UpdateString: @"attachments[0].data" value: @"{{data}}"];
[json UpdateString: @"attachments[0].name" value: @"sample_document"];
[json UpdateString: @"attachments[0].anchorIgnoreIfNotPresent" value: @"false"];
[json UpdateString: @"attachments[0].anchorUnits" value: @"inches"];
[http SetRequestHeader: @"Content-Type" value: @"application/json"];
// Adds the "Authorization: Bearer {{accessToken}}" header.
http.AuthToken = @"{{accessToken}}";
CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes/{{envelopeId}}/attachments" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);
Curl Command
curl -X PUT
-H "Content-Type: application/json"
-H "Authorization: Bearer {{accessToken}}"
-d '{
"attachments": [{
"attachmentId": "123",
"data": {{document}},
"name": "sample_document",
"anchorIgnoreIfNotPresent": "false",
"anchorUnits": "inches"
}]
}'
https://domain.com/{{apiVersion}}/accounts/{{accountId}}/envelopes/{{envelopeId}}/attachments
Postman Collection Item JSON
{
"name": "7. Add an Attachment to Envelope",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{accessToken}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"attachments\": [{\n \"attachmentId\": \"123\",\n \"data\": {{document}},\n \"name\": \"sample_document\",\n \"anchorIgnoreIfNotPresent\": \"false\",\n \"anchorUnits\": \"inches\"\n }]\n}"
},
"url": {
"raw": "{{baseUrl}}/{{apiVersion}}/accounts/{{accountId}}/envelopes/{{envelopeId}}/attachments",
"host": [
"{{baseUrl}}"
],
"path": [
"{{apiVersion}}",
"accounts",
"{{accountId}}",
"envelopes",
"{{envelopeId}}",
"attachments"
]
},
"description": "In this example, we will make further changes to our existing envelope by adding an attachmen to it."
},
"response": [
]
}