autoit / Zoho CRM REST APIs / Transfer Users and Delete Role
Back to Collection Items
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess
; Adds the "Authorization: Bearer <access_token>" header.
$oHttp.AuthToken = "<access_token>"
Local $oResp = $oHttp.QuickRequest("DELETE","https://domain.com/crm/v2.1/settings/roles/738964000002277002?transfer_to_id=738964000002277202")
If ($oHttp.LastMethodSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "roles": [
; {
; "code": "SUCCESS",
; "details": {
; "id": "738964000002277002"
; },
; "message": "Role Deleted",
; "status": "success"
; }
; ]
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Local $sCode
Local $sId
Local $sMessage
Local $status
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("roles")
While $i < $iCount_i
$oJResp.I = $i
$sCode = $oJResp.StringOf("roles[i].code")
$sId = $oJResp.StringOf("roles[i].details.id")
$sMessage = $oJResp.StringOf("roles[i].message")
$status = $oJResp.StringOf("roles[i].status")
$i = $i + 1
Wend
Curl Command
curl -X DELETE
-H "Authorization: Bearer <access_token>"
https://domain.com/crm/v2.1/settings/roles/738964000002277002?transfer_to_id=738964000002277202
Postman Collection Item JSON
{
"name": "Transfer Users and Delete Role",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access-token}}",
"type": "string"
}
]
},
"method": "DELETE",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/738964000002277002?transfer_to_id=738964000002277202",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"738964000002277002"
],
"query": [
{
"key": "transfer_to_id",
"value": "738964000002277202"
}
]
},
"description": "To transfer users and delete a role."
},
"response": [
{
"name": "SUCCESS RESPONSE",
"originalRequest": {
"method": "DELETE",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/738964000002277002?transfer_to_id=738964000002277202",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"738964000002277002"
],
"query": [
{
"key": "transfer_to_id",
"value": "738964000002277202"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:34:13 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\": \"738964000002277002\"\n },\n \"message\": \"Role Deleted\",\n \"status\": \"success\"\n }\n ]\n}"
},
{
"name": "INVALID_REQUEST_METHOD",
"originalRequest": {
"method": "PATCH",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/738964000002277002?transfer_to_id=738964000002277202",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"738964000002277002"
],
"query": [
{
"key": "transfer_to_id",
"value": "738964000002277202"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:35:11 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": "DELETE",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/738964000002277002?transfer_to_id=738964000002277202",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"738964000002277002"
],
"query": [
{
"key": "transfer_to_id",
"value": "738964000002277202"
}
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:35:31 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 (Role ID)",
"originalRequest": {
"method": "DELETE",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/73896400000227700?transfer_to_id=738964000002277202",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"73896400000227700"
],
"query": [
{
"key": "transfer_to_id",
"value": "738964000002277202"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:35:54 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "121"
},
{
"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 \"code\": \"INVALID_DATA\",\n \"details\": {\n \"resource_path_index\": 2\n },\n \"message\": \"the id given seems to be invalid\",\n \"status\": \"error\"\n}"
},
{
"name": "REQUIRED_PARAM_MISSING",
"originalRequest": {
"method": "DELETE",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/738964000002277002",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"738964000002277002"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:36:27 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "141"
},
{
"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\": \"REQUIRED_PARAM_MISSING\",\n \"details\": {\n \"param\": \"transfer_to_id\"\n },\n \"message\": \"One of the expected parameter is missing\",\n \"status\": \"error\"\n}"
},
{
"name": "INVALID_DATA (Role ID and Transfer To ID are same)",
"originalRequest": {
"method": "DELETE",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/738964000002277202?transfer_to_id=738964000002277202",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"738964000002277202"
],
"query": [
{
"key": "transfer_to_id",
"value": "738964000002277202"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:38:46 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "155"
},
{
"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 \"code\": \"INVALID_DATA\",\n \"details\": {\n \"role_status\": \"subordinate | invalid | same_role\",\n \"param_name\": \"transfer_to_id\"\n },\n \"message\": \"invalid id\",\n \"status\": \"error\"\n}"
},
{
"name": "UNABLE_TO_PARSE_DATA_TYPE",
"originalRequest": {
"method": "DELETE",
"header": [
],
"url": {
"raw": "{{api-domain}}/crm/v2.1/settings/roles/738964000002277202?transfer_to_id=\"ID\"",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"settings",
"roles",
"738964000002277202"
],
"query": [
{
"key": "transfer_to_id",
"value": "\"ID\""
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 15 Jun 2021 10:40:28 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "136"
},
{
"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\": \"UNABLE_TO_PARSE_DATA_TYPE\",\n \"details\": {},\n \"message\": \"either the request body or parameters is in wrong format\",\n \"status\": \"error\"\n}"
}
]
}