PureBasic / Zoho CRM REST APIs / Update Specific Information of a Notification
Back to Collection Items
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
; Use this online tool to generate code from sample JSON: Generate Code to Create JSON
; The following JSON is sent in the request body.
; {
; "watch": [
; {
; "channel_id": "1000000068001",
; "events": [
; "Solutions.create",
; "Price_Books.delete"
; ],
; "channel_expiry": "2018-02-02T11:30:00+05:30"
; },
; {
; "channel_id": "1000000068002",
; "events": [
; "Deals.edit"
; ],
; "channel_expiry": "2018-02-02T11:30:00+05:30"
; }
; ]
; }
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"watch[0].channel_id","1000000068001")
CkJsonObject::ckUpdateString(json,"watch[0].events[0]","Solutions.create")
CkJsonObject::ckUpdateString(json,"watch[0].events[1]","Price_Books.delete")
CkJsonObject::ckUpdateString(json,"watch[0].channel_expiry","2018-02-02T11:30:00+05:30")
CkJsonObject::ckUpdateString(json,"watch[1].channel_id","1000000068002")
CkJsonObject::ckUpdateString(json,"watch[1].events[0]","Deals.edit")
CkJsonObject::ckUpdateString(json,"watch[1].channel_expiry","2018-02-02T11:30:00+05:30")
; Adds the "Authorization: Bearer <access_token>" header.
CkHttp::setCkAuthToken(http, "<access_token>")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
resp.i = CkHttp::ckPTextSb(http,"PATCH","https://domain.com/crm/v2/actions/watch",sbRequestBody,"utf-8","application/json",0,0)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
ProcedureReturn
EndIf
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttpResponse::ckGetBodySb(resp,sbResponseBody)
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jResp,sbResponseBody)
CkJsonObject::setCkEmitCompact(jResp, 0)
Debug "Response Body:"
Debug CkJsonObject::ckEmit(jResp)
respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
Debug "Response Status Code = " + Str(respStatusCode)
If respStatusCode >= 400
Debug "Response Header:"
Debug CkHttpResponse::ckHeader(resp)
Debug "Failed."
CkHttpResponse::ckDispose(resp)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndIf
CkHttpResponse::ckDispose(resp)
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "watch": [
; {
; "code": "SUCCESS",
; "details": {
; "events": [
; {
; "channel_expiry": "2021-05-11T16:48:40+00:00",
; "resource_uri": "https://crm.localzoho.com/crm/v2/Solutions",
; "resource_id": "738964000000000161",
; "resource_name": "Solutions",
; "channel_id": "1000000068001"
; },
; {
; "channel_expiry": "2021-05-11T16:48:40+00:00",
; "resource_uri": "https://crm.localzoho.com/crm/v2/Price_Books",
; "resource_id": "738964000000000167",
; "resource_name": "Price_Books",
; "channel_id": "1000000068001"
; }
; ]
; },
; "message": "Successfully updated the subscribe details",
; "status": "success"
; },
; {
; "code": "SUCCESS",
; "details": {
; "events": [
; {
; "channel_expiry": "2021-05-11T16:48:40+00:00",
; "resource_uri": "https://crm.localzoho.com/crm/v2/Deals",
; "resource_id": "738964000000000131",
; "resource_name": "Deals",
; "channel_id": "1000000068002"
; }
; ]
; },
; "message": "Successfully updated the subscribe details",
; "status": "success"
; }
; ]
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
code.s
message.s
status.s
j.i
count_j.i
channel_expiry.s
resource_uri.s
resource_id.s
resource_name.s
channel_id.s
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"watch")
While i < count_i
CkJsonObject::setCkI(jResp, i)
code = CkJsonObject::ckStringOf(jResp,"watch[i].code")
message = CkJsonObject::ckStringOf(jResp,"watch[i].message")
status = CkJsonObject::ckStringOf(jResp,"watch[i].status")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"watch[i].details.events")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
channel_expiry = CkJsonObject::ckStringOf(jResp,"watch[i].details.events[j].channel_expiry")
resource_uri = CkJsonObject::ckStringOf(jResp,"watch[i].details.events[j].resource_uri")
resource_id = CkJsonObject::ckStringOf(jResp,"watch[i].details.events[j].resource_id")
resource_name = CkJsonObject::ckStringOf(jResp,"watch[i].details.events[j].resource_name")
channel_id = CkJsonObject::ckStringOf(jResp,"watch[i].details.events[j].channel_id")
j = j + 1
Wend
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
Curl Command
curl -X PATCH
-H "Authorization: Bearer <access_token>"
-d '{
"watch": [
{
"channel_id": "1000000068001",
"events": [
"Solutions.create",
"Price_Books.delete"
],
"channel_expiry": "2018-02-02T11:30:00+05:30"
},
{
"channel_id": "1000000068002",
"events": [
"Deals.edit"
],
"channel_expiry": "2018-02-02T11:30:00+05:30"
}
]
}'
https://domain.com/crm/v2/actions/watch
Postman Collection Item JSON
{
"name": "Update Specific Information of a Notification",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access-token}}",
"type": "string"
}
]
},
"method": "PATCH",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"watch\": [\n {\n \"channel_id\": \"1000000068001\",\n \"events\": [\n \"Solutions.create\",\n \"Price_Books.delete\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n },\n {\n \"channel_id\": \"1000000068002\",\n \"events\": [\n \"Deals.edit\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/actions/watch",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"actions",
"watch"
]
},
"description": "To update only specific details of a specific notification enabled by the user. All the provided details would be persisted and rest of the details will not be removed."
},
"response": [
{
"name": "SUCCESS RESPONSE",
"originalRequest": {
"method": "PATCH",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"watch\": [\n {\n \"channel_id\": \"1000000068001\",\n \"events\": [\n \"Solutions.create\",\n \"Price_Books.delete\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n },\n {\n \"channel_id\": \"1000000068002\",\n \"events\": [\n \"Deals.edit\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/actions/watch",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"actions",
"watch"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 11 May 2021 15:48:34 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "836"
},
{
"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-05-11T16:40:31+00:00"
},
{
"key": "clientVersion",
"value": "4027076"
},
{
"key": "clientsubVersion",
"value": "748ecbe82ec7e144b66ee25f264bbd88"
},
{
"key": "Content-Disposition",
"value": "attachment; filename=response.json"
},
{
"key": "Content-Language",
"value": "en-US"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=15768000"
}
],
"cookie": [
],
"body": "{\n \"watch\": [\n {\n \"code\": \"SUCCESS\",\n \"details\": {\n \"events\": [\n {\n \"channel_expiry\": \"2021-05-11T16:48:40+00:00\",\n \"resource_uri\": \"https://crm.localzoho.com/crm/v2/Solutions\",\n \"resource_id\": \"738964000000000161\",\n \"resource_name\": \"Solutions\",\n \"channel_id\": \"1000000068001\"\n },\n {\n \"channel_expiry\": \"2021-05-11T16:48:40+00:00\",\n \"resource_uri\": \"https://crm.localzoho.com/crm/v2/Price_Books\",\n \"resource_id\": \"738964000000000167\",\n \"resource_name\": \"Price_Books\",\n \"channel_id\": \"1000000068001\"\n }\n ]\n },\n \"message\": \"Successfully updated the subscribe details\",\n \"status\": \"success\"\n },\n {\n \"code\": \"SUCCESS\",\n \"details\": {\n \"events\": [\n {\n \"channel_expiry\": \"2021-05-11T16:48:40+00:00\",\n \"resource_uri\": \"https://crm.localzoho.com/crm/v2/Deals\",\n \"resource_id\": \"738964000000000131\",\n \"resource_name\": \"Deals\",\n \"channel_id\": \"1000000068002\"\n }\n ]\n },\n \"message\": \"Successfully updated the subscribe details\",\n \"status\": \"success\"\n }\n ]\n}"
},
{
"name": "INVALID_URL_PATTERN",
"originalRequest": {
"method": "PATCH",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"watch\": [\n {\n \"channel_id\": \"1000000068001\",\n \"events\": [\n \"Solutions.create\",\n \"Price_Books.delete\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n },\n {\n \"channel_id\": \"1000000068002\",\n \"events\": [\n \"Deals.edit\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/actions/watc",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"actions",
"watc"
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 11 May 2021 15:48:50 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "131"
},
{
"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-05-11T16:40:31+00:00"
},
{
"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_URL_PATTERN\",\n \"details\": {},\n \"message\": \"Please check if the URL trying to access is a correct one\",\n \"status\": \"error\"\n}"
},
{
"name": "AUTHENTICATION_FAILURE",
"originalRequest": {
"method": "PATCH",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"watch\": [\n {\n \"channel_id\": \"1000000068001\",\n \"events\": [\n \"Solutions.create\",\n \"Price_Books.delete\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n },\n {\n \"channel_id\": \"1000000068002\",\n \"events\": [\n \"Deals.edit\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/actions/watc",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"actions",
"watc"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 11 May 2021 15:49:04 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_REQUEST_METHOD",
"originalRequest": {
"method": "COPY",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"watch\": [\n {\n \"channel_id\": \"1000000068001\",\n \"events\": [\n \"Solutions.create\",\n \"Price_Books.delete\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n },\n {\n \"channel_id\": \"1000000068002\",\n \"events\": [\n \"Deals.edit\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/actions/watc",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"actions",
"watc"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Tue, 11 May 2021 15:49:16 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_REQUEST",
"originalRequest": {
"method": "PATCH",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"watch\": [\n {\n \"channel_id\": \"1000000068001\",\n \"events\": [\n \"Solutions.create\",\n \"Price_Books.delete\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n },\n {\n \"channel_id\": \"1000000068002\",\n \"events\": [\n \"Deals.edit\"\n ],\n \"channel_expiry\": \"2018-02-02T11:30:00+05:30\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/actions/watch",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"actions",
"watch"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Thu, 13 May 2021 06:48:26 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "192"
},
{
"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\": \"INVALID_REQUEST\",\n \"details\": {},\n \"message\": \"unable to process your request. please verify whether you have entered proper method name, parameter and parameter values.\",\n \"status\": \"error\"\n}"
}
]
}