phpExt / Zoho CRM REST APIs / Add Contact Roles to a Specific Deal
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.
// {
// "data": [
// {
// "Contact_Role": "Purchasing"
// }
// ]
// }
$json = new CkJsonObject();
$json->UpdateString('data[0].Contact_Role','Purchasing');
// 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/Deals/738964000001919043/Contact_Roles/738964000002224050',$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)
// {
// "data": [
// {
// "code": "SUCCESS",
// "details": {
// "id": "738964000002224050"
// },
// "message": "relation added",
// "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('data');
while ($i < $count_i) {
$jResp->put_I($i);
$code = $jResp->stringOf('data[i].code');
$Id = $jResp->stringOf('data[i].details.id');
$message = $jResp->stringOf('data[i].message');
$status = $jResp->stringOf('data[i].status');
$i = $i + 1;
}
?>
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"data": [
{
"Contact_Role": "Purchasing"
}
]
}'
https://domain.com/crm/v2/Deals/738964000001919043/Contact_Roles/738964000002224050
Postman Collection Item JSON
{
"name": "Add Contact Roles to a Specific Deal",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access-token}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/738964000001919043/Contact_Roles/738964000002224050",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"738964000001919043",
"Contact_Roles",
"738964000002224050"
]
}
},
"response": [
{
"name": "SUCCESS RESPONSE",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/738964000001919043/Contact_Roles/738964000002224050",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"738964000001919043",
"Contact_Roles",
"738964000002224050"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Fri, 18 Jun 2021 13:26:47 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "113"
},
{
"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-18T13:56:39+00:00"
},
{
"key": "clientVersion",
"value": "4126581"
},
{
"key": "clientsubVersion",
"value": "4db5c971143ce609008746cb1d40f588"
},
{
"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 \"data\": [\n {\n \"code\": \"SUCCESS\",\n \"details\": {\n \"id\": \"738964000002224050\"\n },\n \"message\": \"relation added\",\n \"status\": \"success\"\n }\n ]\n}"
},
{
"name": "INVALID_MODULE",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deal/738964000001919043/Contact_Roles/738964000002224050",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deal",
"738964000001919043",
"Contact_Roles",
"738964000002224050"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Sat, 19 Jun 2021 12:48:14 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "110"
},
{
"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-19T13:46:59+00:00"
},
{
"key": "clientVersion",
"value": "4129594"
},
{
"key": "clientsubVersion",
"value": "e19f9ad0a8e8124688b3545413dd1f46"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"code\": \"INVALID_MODULE\",\n \"details\": {},\n \"message\": \"the module name given seems to be invalid\",\n \"status\": \"error\"\n}"
},
{
"name": "MANDATORY_NOT_FOUND",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/738964000001919043/Contact_Roles",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"738964000001919043",
"Contact_Roles"
]
}
},
"status": "Accepted",
"code": 202,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Sat, 19 Jun 2021 12:48:43 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "123"
},
{
"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-19T13:46:59+00:00"
},
{
"key": "clientVersion",
"value": "4129594"
},
{
"key": "clientsubVersion",
"value": "e19f9ad0a8e8124688b3545413dd1f46"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"code\": \"MANDATORY_NOT_FOUND\",\n \"details\": {\n \"api_name\": \"id\"\n },\n \"message\": \"required field not found\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "INVALID_REQUEST_METHOD",
"originalRequest": {
"method": "COPY",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/738964000001919043/Contact_Roles/738964000002224050",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"738964000001919043",
"Contact_Roles",
"738964000002224050"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Sat, 19 Jun 2021 12:49:05 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": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/738964000001919043/Contact_Roles/738964000002224050",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"738964000001919043",
"Contact_Roles",
"738964000002224050"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Sat, 19 Jun 2021 12:49:20 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",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/738964000001919043/Contact_Roles/73896400000222405",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"738964000001919043",
"Contact_Roles",
"73896400000222405"
]
}
},
"status": "Accepted",
"code": 202,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Sat, 19 Jun 2021 12:49:42 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "124"
},
{
"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-19T13:46:59+00:00"
},
{
"key": "clientVersion",
"value": "4129594"
},
{
"key": "clientsubVersion",
"value": "e19f9ad0a8e8124688b3545413dd1f46"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"code\": \"INVALID_DATA\",\n \"details\": {\n \"api_name\": \"id\"\n },\n \"message\": \"the id given seems to be invalid\",\n \"status\": \"error\"\n }\n ]\n}"
},
{
"name": "INVALID_DATA",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasing\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/73896400000191904/Contact_Roles/738964000002224050",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"73896400000191904",
"Contact_Roles",
"738964000002224050"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Sat, 19 Jun 2021 12:50:07 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "107"
},
{
"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-19T13:46:59+00:00"
},
{
"key": "clientVersion",
"value": "4129594"
},
{
"key": "clientsubVersion",
"value": "e19f9ad0a8e8124688b3545413dd1f46"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"code\": \"INVALID_DATA\",\n \"details\": {},\n \"message\": \"the related id given seems to be invalid\",\n \"status\": \"error\"\n}"
},
{
"name": "INVALID_DATA",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": [\n {\n \"Contact_Role\": \"Purchasig\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Deals/738964000001919043/Contact_Roles/738964000002224050",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Deals",
"738964000001919043",
"Contact_Roles",
"738964000002224050"
]
}
},
"status": "Accepted",
"code": 202,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Sat, 19 Jun 2021 12:51:13 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "114"
},
{
"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-19T13:46:59+00:00"
},
{
"key": "clientVersion",
"value": "4129594"
},
{
"key": "clientsubVersion",
"value": "e19f9ad0a8e8124688b3545413dd1f46"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"code\": \"INVALID_DATA\",\n \"details\": {\n \"api_name\": \"Contact_Role\"\n },\n \"message\": \"invalid data\",\n \"status\": \"error\"\n }\n ]\n}"
}
]
}