PureBasic / Support API / Update Custom Ticket Status
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
CkHttp::setCkBasicAuth(http, 1)
CkHttp::setCkLogin(http, "login")
CkHttp::setCkPassword(http, "password")
; Use this online tool to generate code from sample JSON: Generate Code to Create JSON
; The following JSON is sent in the request body.
; {
; "custom_status": {
; "active": "<boolean>",
; "agent_label": "<string>",
; "description": "<string>",
; "end_user_description": "<string>",
; "end_user_label": "<string>"
; }
; }
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"custom_status.active","<boolean>")
CkJsonObject::ckUpdateString(json,"custom_status.agent_label","<string>")
CkJsonObject::ckUpdateString(json,"custom_status.description","<string>")
CkJsonObject::ckUpdateString(json,"custom_status.end_user_description","<string>")
CkJsonObject::ckUpdateString(json,"custom_status.end_user_label","<string>")
CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
CkHttp::ckSetRequestHeader(http,"Accept","application/json")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
resp.i = CkHttp::ckPTextSb(http,"PUT","https://example.zendesk.com/api/v2/custom_statuses/:custom_status_id",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)
; {
; "custom_status": {
; "status_category": "open",
; "agent_label": "<string>",
; "active": "<boolean>",
; "created_at": "<dateTime>",
; "default": "<boolean>",
; "description": "<string>",
; "end_user_description": "<string>",
; "end_user_label": "<string>",
; "id": "<integer>",
; "raw_agent_label": "<string>",
; "raw_description": "<string>",
; "raw_end_user_description": "<string>",
; "raw_end_user_label": "<string>",
; "updated_at": "<dateTime>"
; }
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Status_category.s = CkJsonObject::ckStringOf(jResp,"custom_status.status_category")
Agent_label.s = CkJsonObject::ckStringOf(jResp,"custom_status.agent_label")
Active.s = CkJsonObject::ckStringOf(jResp,"custom_status.active")
Created_at.s = CkJsonObject::ckStringOf(jResp,"custom_status.created_at")
Default.s = CkJsonObject::ckStringOf(jResp,"custom_status.default")
Description.s = CkJsonObject::ckStringOf(jResp,"custom_status.description")
End_user_description.s = CkJsonObject::ckStringOf(jResp,"custom_status.end_user_description")
End_user_label.s = CkJsonObject::ckStringOf(jResp,"custom_status.end_user_label")
Id.s = CkJsonObject::ckStringOf(jResp,"custom_status.id")
Raw_agent_label.s = CkJsonObject::ckStringOf(jResp,"custom_status.raw_agent_label")
Raw_description.s = CkJsonObject::ckStringOf(jResp,"custom_status.raw_description")
Raw_end_user_description.s = CkJsonObject::ckStringOf(jResp,"custom_status.raw_end_user_description")
Raw_end_user_label.s = CkJsonObject::ckStringOf(jResp,"custom_status.raw_end_user_label")
Updated_at.s = CkJsonObject::ckStringOf(jResp,"custom_status.updated_at")
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
Curl Command
curl -u login:password -X PUT
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"custom_status": {
"active": "<boolean>",
"agent_label": "<string>",
"description": "<string>",
"end_user_description": "<string>",
"end_user_label": "<string>"
}
}'
https://example.zendesk.com/api/v2/custom_statuses/:custom_status_id
Postman Collection Item JSON
{
"name": "Update Custom Ticket Status",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"custom_status\": {\n \"active\": \"<boolean>\",\n \"agent_label\": \"<string>\",\n \"description\": \"<string>\",\n \"end_user_description\": \"<string>\",\n \"end_user_label\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/custom_statuses/:custom_status_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_statuses",
":custom_status_id"
],
"variable": [
{
"key": "custom_status_id",
"value": "<integer>"
}
]
},
"description": "Takes a `custom_status` object that specifies the properties to update.\n\n#### Allowed For\n\n* Admins\n"
},
"response": [
{
"name": "Updated",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"custom_status\": {\n \"active\": \"<boolean>\",\n \"agent_label\": \"<string>\",\n \"description\": \"<string>\",\n \"end_user_description\": \"<string>\",\n \"end_user_label\": \"<string>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/custom_statuses/:custom_status_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_statuses",
":custom_status_id"
],
"variable": [
{
"key": "custom_status_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"custom_status\": {\n \"status_category\": \"open\",\n \"agent_label\": \"<string>\",\n \"active\": \"<boolean>\",\n \"created_at\": \"<dateTime>\",\n \"default\": \"<boolean>\",\n \"description\": \"<string>\",\n \"end_user_description\": \"<string>\",\n \"end_user_label\": \"<string>\",\n \"id\": \"<integer>\",\n \"raw_agent_label\": \"<string>\",\n \"raw_description\": \"<string>\",\n \"raw_end_user_description\": \"<string>\",\n \"raw_end_user_label\": \"<string>\",\n \"updated_at\": \"<dateTime>\"\n }\n}"
}
]
}