Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global_Ref.html">Global Unlock Sample for sample code.
http := chilkat.NewHttp()
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
// }
// ]
// }
json := chilkat.NewJsonObject()
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.SetAuthToken("<access_token>")
sbRequestBody := chilkat.NewStringBuilder()
json.EmitSb(sbRequestBody)
resp := http.PTextSb("PUT","https://domain.com/crm/v2.1/settings/roles",sbRequestBody,"utf-8","application/json",false,false)
if http.LastMethodSuccess() == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
json.DisposeJsonObject()
sbRequestBody.DisposeStringBuilder()
return
}
sbResponseBody := chilkat.NewStringBuilder()
resp.GetBodySb(sbResponseBody)
jResp := chilkat.NewJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jResp.Emit())
respStatusCode := resp.StatusCode()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(resp.Header())
fmt.Println("Failed.")
resp.DisposeHttpResponse()
http.DisposeHttp()
json.DisposeJsonObject()
sbRequestBody.DisposeStringBuilder()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
return
}
resp.DisposeHttpResponse()
// 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 = new(string)
var Id *string = new(string)
var message *string = new(string)
var status *string = new(string)
i := 0
count_i := jResp.SizeOfArray("roles")
for i < count_i {
jResp.SetI(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
}
http.DisposeHttp()
json.DisposeJsonObject()
sbRequestBody.DisposeStringBuilder()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
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}"
}
]
}