Back to Collection Items
<?php
include("chilkat.php");
// Use "chilkat_9_5_0.php" for versions of Chilkat < 10.0.0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new CkHttp();
// 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
// }
// ]
// }
$json = new CkJsonObject();
$json->UpdateString('roles[0].id','738964000000015969');
$json->UpdateString('roles[0].name','Sales department Head');
$json->UpdateString('roles[0].reporting_to','738964000000015966');
$json->UpdateString('roles[0].forecast_manager','738964000000291009');
$json->UpdateString('roles[0].description','Manage the sales department');
$json->UpdateBool('roles[0].share_with_peers',true);
// Adds the "Authorization: Bearer <access_token>" header.
$http->put_AuthToken('<access_token>');
$sbRequestBody = new CkStringBuilder();
$json->EmitSb($sbRequestBody);
// resp is a CkHttpResponse
$resp = $http->PTextSb('PUT','https://domain.com/crm/v2.1/settings/roles',$sbRequestBody,'utf-8','application/json',false,false);
if ($http->get_LastMethodSuccess() == false) {
print $http->lastErrorText() . "\n";
exit;
}
$sbResponseBody = new CkStringBuilder();
$resp->GetBodySb($sbResponseBody);
$jResp = new CkJsonObject();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(false);
print 'Response Body:' . "\n";
print $jResp->emit() . "\n";
$respStatusCode = $resp->get_StatusCode();
print 'Response Status Code = ' . $respStatusCode . "\n";
if ($respStatusCode >= 400) {
print 'Response Header:' . "\n";
print $resp->header() . "\n";
print 'Failed.' . "\n";
exit;
}
// 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
$i = 0;
$count_i = $jResp->SizeOfArray('roles');
while ($i < $count_i) {
$jResp->put_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}"
}
]
}