Chilkat Online Tools

delphiDll / Zoho CRM REST APIs / Transfer Users and Delete Role

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
code: PWideChar;
Id: PWideChar;
message: PWideChar;
status: PWideChar;
i: Integer;
count_i: Integer;

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

http := CkHttp_Create();

// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');

resp := CkHttp_QuickRequest(http,'DELETE','https://domain.com/crm/v2.1/settings/roles/738964000002277002?transfer_to_id=738964000002277202');
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

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

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'roles');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    code := CkJsonObject__stringOf(jResp,'roles[i].code');
    Id := CkJsonObject__stringOf(jResp,'roles[i].details.id');
    message := CkJsonObject__stringOf(jResp,'roles[i].message');
    status := CkJsonObject__stringOf(jResp,'roles[i].status');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

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