PureBasic / Support API / Create 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>",
; "status_category": "new"
; }
; }
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>")
CkJsonObject::ckUpdateString(json,"custom_status.status_category","new")
CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
CkHttp::ckSetRequestHeader(http,"Accept","application/json")
resp.i = CkHttp::ckPostJson3(http,"https://example.zendesk.com/api/v2/custom_statuses","application/json",json)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
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(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(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
Curl Command
curl -u login:password -X POST
-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>",
"status_category": "new"
}
}'
https://example.zendesk.com/api/v2/custom_statuses
Postman Collection Item JSON
{
"name": "Create Custom Ticket Status",
"request": {
"method": "POST",
"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 \"status_category\": \"new\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/custom_statuses",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_statuses"
]
},
"description": "Takes a `custom_status` object that specifies the custom ticket status properties to create.\n\n#### Allowed For\n\n* Admins\n"
},
"response": [
{
"name": "Created",
"originalRequest": {
"method": "POST",
"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 \"status_category\": \"new\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/custom_statuses",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_statuses"
]
}
},
"status": "Created",
"code": 201,
"_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}"
}
]
}