Chilkat Online Tools

Xojo / Zoho CRM REST APIs / Update Role

Back to Collection Items

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

Dim http As New Chilkat.Http
Dim success As Boolean

// 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
//     }
//   ]
// }

Dim json As New Chilkat.JsonObject
success = json.UpdateString("roles[0].id","738964000000015969")
success = json.UpdateString("roles[0].name","Sales department Head")
success = json.UpdateString("roles[0].reporting_to","738964000000015966")
success = json.UpdateString("roles[0].forecast_manager","738964000000291009")
success = json.UpdateString("roles[0].description","Manage the sales department")
success = json.UpdateBool("roles[0].share_with_peers",True)

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>"

Dim sbRequestBody As New Chilkat.StringBuilder
success = json.EmitSb(sbRequestBody)

Dim resp As Chilkat.HttpResponse
resp = http.PTextSb("PUT","https://domain.com/crm/v2.1/settings/roles",sbRequestBody,"utf-8","application/json",False,False)
If (http.LastMethodSuccess = False) Then
    System.DebugLog(http.LastErrorText)
    Return
End If

Dim sbResponseBody As New Chilkat.StringBuilder
success = resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

System.DebugLog("Response Body:")
System.DebugLog(jResp.Emit())

Dim respStatusCode As Int32
respStatusCode = resp.StatusCode
System.DebugLog("Response Status Code = " + Str(respStatusCode))
If (respStatusCode >= 400) Then
    System.DebugLog("Response Header:")
    System.DebugLog(resp.Header)
    System.DebugLog("Failed.")

    Return
End If

// 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

Dim code As String
Dim Id As String
Dim message As String
Dim status As String

Dim i As Int32
i = 0
Dim count_i As Int32
count_i = jResp.SizeOfArray("roles")
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
Wend

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}"
    }
  ]
}