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.
// {
// "roles": [
// {
// "id": "738964000000015969",
// "name": "Sales department Head",
// "reporting_to": "738964000000015966",
// "forecast_manager": "738964000000291009",
// "description": "Manage the sales department",
// "share_with_peers": true
// }
// ]
// }
let json = CkoJsonObject()
json.UpdateString("roles[0].id", value: "738964000000015969")
json.UpdateString("roles[0].name", value: "Sales department Head")
json.UpdateString("roles[0].reporting_to", value: "738964000000015966")
json.UpdateString("roles[0].forecast_manager", value: "738964000000291009")
json.UpdateString("roles[0].description", value: "Manage the sales department")
json.UpdateBool("roles[0].share_with_peers", value: true)
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>"
let sbRequestBody = CkoStringBuilder()
json.EmitSb(sbRequestBody)
var resp: CkoHttpResponse? = http.PTextSb("PUT", url: "https://domain.com/crm/v2.1/settings/roles", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
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)
// {
// "roles": [
// {
// "code": "SUCCESS",
// "details": {
// "id": "738964000000015969"
// },
// "message": "Role updated",
// "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?
var Id: String?
var message: String?
var status: String?
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("roles").intValue
while i < count_i {
jResp.I = i
code = jResp.StringOf("roles[i].code")
Id = jResp.StringOf("roles[i].details.id")
message = jResp.StringOf("roles[i].message")
status = jResp.StringOf("roles[i].status")
i = i + 1
}
}
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"roles": [
{
"id": "738964000000015969",
"name": "Sales department Head",
"reporting_to": "738964000000015966",
"forecast_manager": "738964000000291009",
"description": "Manage the sales department",
"share_with_peers": true
}
]
}'
https://domain.com/crm/v2.1/settings/roles
Postman Collection Item JSON
{
"name": "Update Role",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access-token}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"id\": \"738964000000015969\",\n \"name\": \"Sales department Head\",\n \"reporting_to\": \"738964000000015966\",\n \"forecast_manager\": \"738964000000291009\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
},
"description": "To update a role in your organization."
},
"response": [
{
"name": "SUCCESS RESPONSE",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"id\": \"738964000000015969\",\n \"name\": \"Sales department Head\",\n \"reporting_to\": \"738964000000015966\",\n \"forecast_manager\": \"738964000002006002\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:25:45 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "112"
},
{
"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-store, no-cache, must-revalidate, private"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-06-15T11:15:35+00:00"
},
{
"key": "clientVersion",
"value": "4116249"
},
{
"key": "clientsubVersion",
"value": "0a372498832d823bc03c7945101b2b5e"
},
{
"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 \"roles\": [\n {\n \"code\": \"SUCCESS\",\n \"details\": {\n \"id\": \"738964000000015969\"\n },\n \"message\": \"Role updated\",\n \"status\": \"success\"\n }\n ]\n}"
},
{
"name": "INVALID_DATA (Forecast Manager ID)",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"id\": \"738964000000015969\",\n \"name\": \"Sales department Head\",\n \"reporting_to\": \"738964000000015966\",\n \"forecast_manager\": \"738964000000291009\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:23:46 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "179"
},
{
"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-store, no-cache, must-revalidate, private"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-06-15T11:15:35+00:00"
},
{
"key": "clientVersion",
"value": "4116249"
},
{
"key": "clientsubVersion",
"value": "0a372498832d823bc03c7945101b2b5e"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"roles\": [\n {\n \"code\": \"INVALID_DATA\",\n \"details\": {\n \"api_name\": \"id\",\n \"json_path\": \"$.roles[0].forecast_manager.id\"\n },\n \"message\": \"Forecast Manager not present in this Role\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "INVALID_REQUEST_METHOD",
"originalRequest": {
"method": "PATCH",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"id\": \"738964000000015969\",\n \"name\": \"Sales department Head\",\n \"reporting_to\": \"738964000000015966\",\n \"forecast_manager\": \"738964000000291009\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:26:24 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": "INVALID_DATA (Role ID)",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"id\": \"73896400000001596\",\n \"name\": \"Sales department Head\",\n \"reporting_to\": \"738964000000015966\",\n \"forecast_manager\": \"738964000000291009\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:26:48 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "152"
},
{
"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-store, no-cache, must-revalidate, private"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-06-15T11:15:35+00:00"
},
{
"key": "clientVersion",
"value": "4116249"
},
{
"key": "clientsubVersion",
"value": "0a372498832d823bc03c7945101b2b5e"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"roles\": [\n {\n \"code\": \"INVALID_DATA\",\n \"details\": {\n \"api_name\": \"id\",\n \"json_path\": \"$.roles[0].id\"\n },\n \"message\": \"the given role id seems invalid\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "INVALID_DATA (Reporting To ID)",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"id\": \"738964000000015969\",\n \"name\": \"Sales department Head\",\n \"reporting_to\": \"73896400000001596\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:30:30 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "165"
},
{
"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-store, no-cache, must-revalidate, private"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-06-15T11:15:35+00:00"
},
{
"key": "clientVersion",
"value": "4116249"
},
{
"key": "clientsubVersion",
"value": "0a372498832d823bc03c7945101b2b5e"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"roles\": [\n {\n \"code\": \"INVALID_DATA\",\n \"details\": {\n \"api_name\": \"id\",\n \"json_path\": \"$.roles[0].reporting_to.id\"\n },\n \"message\": \"the given role id seems invalid\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "DUPLICATE_DATA",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"id\": \"738964000002277002\",\n \"name\": \"Manager\",\n \"reporting_to\": \"738964000000015966\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:32:05 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "188"
},
{
"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-store, no-cache, must-revalidate, private"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-06-15T11:15:35+00:00"
},
{
"key": "clientVersion",
"value": "4116249"
},
{
"key": "clientsubVersion",
"value": "0a372498832d823bc03c7945101b2b5e"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"roles\": [\n {\n \"code\": \"DUPLICATE_DATA\",\n \"details\": {\n \"api_name\": \"name\",\n \"json_path\": \"$.roles[0].name\"\n },\n \"message\": \"Failed to add role since role with same name is already exist\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "MANDATORY_NOT_FOUND",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"roles\": [\n {\n \"name\": \"Manager\",\n \"reporting_to\": \"738964000000015966\",\n \"description\": \"Manage the sales department\",\n \"share_with_peers\": true\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:32:25 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "152"
},
{
"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-store, no-cache, must-revalidate, private"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-ACCESSTOKEN-RESET",
"value": "2021-06-15T11:15:35+00:00"
},
{
"key": "clientVersion",
"value": "4116249"
},
{
"key": "clientsubVersion",
"value": "0a372498832d823bc03c7945101b2b5e"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"roles\": [\n {\n \"code\": \"MANDATORY_NOT_FOUND\",\n \"details\": {\n \"api_name\": \"id\",\n \"json_path\": \"$.roles[0].id\"\n },\n \"message\": \"required field not found\",\n \"status\": \"error\"\n }\n ]\n}"
}
]
}