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
let req = CkoHttpRequest()!
req.httpVerb = "POST"
req.path = "/crm/v2.1/Leads/{{record_id}}/photo"
req.contentType = "multipart/form-data"
success = req.addFile(forUpload2: "file", path: " path to file", contentType: "application/octet-stream")
req.addHeader("Authorization", value: "Bearer <access_token>")
req.addHeader("Expect", value: "100-continue")
var resp: CkoHttpResponse? = http.synchronousRequest("domain.com", port: 443, ssl: true, req: req)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
let sbResponseBody = CkoStringBuilder()!
resp!.getBodySb(sbResponseBody)
let jResp = CkoJsonObject()!
jResp.loadSb(sbResponseBody)
jResp.emitCompact = false
print("Response Body:")
print("\(jResp.emit()!)")
var respStatusCode: Int = resp!.statusCode.intValue
print("Response Status Code = \(respStatusCode)")
if respStatusCode >= 400 {
print("Response Header:")
print("\(resp!.header!)")
print("Failed.")
resp = nil
return
}
resp = nil
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "code": "SUCCESS",
// "details": {},
// "message": "photo uploaded successfully",
// "status": "success"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
var code: String? = jResp.string(of: "code")
var message: String? = jResp.string(of: "message")
var status: String? = jResp.string(of: "status")
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
--form 'file=@"/path/to/file"'
https://domain.com/crm/v2.1/Leads/{{record_id}}/photo
Postman Collection Item JSON
{
"name": "Leads",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access-token}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Desktop/image.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Leads/{{record_id}}/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Leads",
"{{record_id}}",
"photo"
]
},
"description": "To add record image. You must include the photo in the request with content type as multipart/form data."
},
"response": [
{
"name": "SUCCESS RESPONSE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Downloads/508939.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Leads/4150868000004943003/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Leads",
"4150868000004943003",
"photo"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 12:12:33 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "90"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-03T18:26:34+05:30"
},
{
"key": "clientVersion",
"value": "4002155"
},
{
"key": "clientsubVersion",
"value": "bfb2326744b42e5c869a705645ac0006"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=63072000"
}
],
"cookie": [
],
"body": "{\n \"code\": \"SUCCESS\",\n \"details\": {},\n \"message\": \"photo uploaded successfully\",\n \"status\": \"success\"\n}"
},
{
"name": "INVALID_MODULE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Downloads/508939.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Lead/4150868000004943003/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Lead",
"4150868000004943003",
"photo"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 12:12:58 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "133"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-03T18:26:34+05:30"
},
{
"key": "clientVersion",
"value": "4002155"
},
{
"key": "clientsubVersion",
"value": "bfb2326744b42e5c869a705645ac0006"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"code\": \"INVALID_MODULE\",\n \"details\": {\n \"resource_path_index\": 0\n },\n \"message\": \"the module name given seems to be invalid\",\n \"status\": \"error\"\n}"
},
{
"name": "INVALID_REQUEST_METHOD",
"originalRequest": {
"method": "PATCH",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Downloads/508939.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Leads/4150868000004943003/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Leads",
"4150868000004943003",
"photo"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 12:14:19 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "124"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Frame-Options",
"value": "deny"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
}
],
"cookie": [
],
"body": "{\n \"code\": \"INVALID_REQUEST_METHOD\",\n \"details\": {},\n \"message\": \"The http request method type is not a valid one\",\n \"status\": \"error\"\n}"
},
{
"name": "AUTHENTICATION_FAILURE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Downloads/508939.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Leads/4150868000004943003/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Leads",
"4150868000004943003",
"photo"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 12:14:39 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "98"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Download-Options",
"value": "noopen"
}
],
"cookie": [
],
"body": "{\n \"code\": \"AUTHENTICATION_FAILURE\",\n \"details\": {},\n \"message\": \"Authentication failed\",\n \"status\": \"error\"\n}"
},
{
"name": "INVALID_DATA (File type)",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Downloads/Bulk_Write_Contacts.csv"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Leads/4150868000004943003/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Leads",
"4150868000004943003",
"photo"
]
}
},
"status": "Unsupported Media Type",
"code": 415,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 12:15:32 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "84"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Download-Options",
"value": "noopen"
}
],
"cookie": [
],
"body": "{\n \"code\": \"INVALID_DATA\",\n \"details\": {},\n \"message\": \"invalid file type\",\n \"status\": \"error\"\n}"
},
{
"name": "INVALID_DATA (Record ID)",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Desktop/image.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Leads/415086800000494300/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Leads",
"415086800000494300",
"photo"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 12:18:58 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "99"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-03T18:26:34+05:30"
},
{
"key": "clientVersion",
"value": "4002155"
},
{
"key": "clientsubVersion",
"value": "bfb2326744b42e5c869a705645ac0006"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"code\": \"INVALID_DATA\",\n \"details\": {},\n \"message\": \"the id given seems to be invalid\",\n \"status\": \"error\"\n}"
},
{
"name": "FILE_SIZE_MORE_THAN_ALLOWED_SIZE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Downloads/laika-notebooks-pONH9yZ-wXg-unsplash.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Leads/4150868000004943003/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Leads",
"4150868000004943003",
"photo"
]
}
},
"status": "Unsupported Media Type",
"code": 415,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 12:16:48 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "204"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-05-03T18:26:34+05:30"
},
{
"key": "clientVersion",
"value": "4002155"
},
{
"key": "clientsubVersion",
"value": "bfb2326744b42e5c869a705645ac0006"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"code\": \"FILE_SIZE_MORE_THAN_ALLOWED_SIZE\",\n \"details\": {},\n \"message\": \"Image resolution is more than allowed limit 10 MP, please upload after resizing image dimension or choose other image\",\n \"status\": \"error\"\n}"
},
{
"name": "OAUTH_SCOPE_MISMATCH",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/Users/sneha-9300/Desktop/image.jpg"
}
]
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/Lead/4150868000004943003/photo",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Lead",
"4150868000004943003",
"photo"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 03 May 2021 13:31:15 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "113"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Referrer-Policy",
"value": "strict-origin"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Download-Options",
"value": "noopen"
}
],
"cookie": [
],
"body": "{\n \"code\": \"OAUTH_SCOPE_MISMATCH\",\n \"details\": {},\n \"message\": \"invalid oauth scope to access this URL\",\n \"status\": \"error\"\n}"
}
]
}