PureBasic / Support API / Create Trigger Category
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.
; {
; "trigger_category": {
; "name": "<string>",
; "position": "<long>"
; }
; }
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"trigger_category.name","<string>")
CkJsonObject::ckUpdateString(json,"trigger_category.position","<long>")
CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
CkHttp::ckSetRequestHeader(http,"Accept","application/json")
resp.i = CkHttp::ckPostJson3(http,"https://example.zendesk.com/api/v2/trigger_categories","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)
; {
; "trigger_category": {
; "created_at": "<string>",
; "id": "<string>",
; "name": "<string>",
; "position": "<long>",
; "updated_at": "<string>"
; }
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Created_at.s = CkJsonObject::ckStringOf(jResp,"trigger_category.created_at")
Id.s = CkJsonObject::ckStringOf(jResp,"trigger_category.id")
Name.s = CkJsonObject::ckStringOf(jResp,"trigger_category.name")
Position.s = CkJsonObject::ckStringOf(jResp,"trigger_category.position")
Updated_at.s = CkJsonObject::ckStringOf(jResp,"trigger_category.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 '{
"trigger_category": {
"name": "<string>",
"position": "<long>"
}
}'
https://example.zendesk.com/api/v2/trigger_categories
Postman Collection Item JSON
{
"name": "Create Trigger Category",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"trigger_category\": {\n \"name\": \"<string>\",\n \"position\": \"<long>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/trigger_categories",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"trigger_categories"
]
},
"description": "Creates a trigger category."
},
"response": [
{
"name": "The created trigger category",
"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 \"trigger_category\": {\n \"name\": \"<string>\",\n \"position\": \"<long>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/trigger_categories",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"trigger_categories"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"trigger_category\": {\n \"created_at\": \"<string>\",\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"position\": \"<long>\",\n \"updated_at\": \"<string>\"\n }\n}"
},
{
"name": "Error",
"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 \"trigger_category\": {\n \"name\": \"<string>\",\n \"position\": \"<long>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/trigger_categories",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"trigger_categories"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n {\n \"code\": \"<string>\",\n \"title\": \"<string>\",\n \"detail\": \"<string>\",\n \"id\": \"<string>\",\n \"links\": {},\n \"source\": {},\n \"status\": \"<string>\"\n },\n {\n \"code\": \"<string>\",\n \"title\": \"<string>\",\n \"detail\": \"<string>\",\n \"id\": \"<string>\",\n \"links\": {},\n \"source\": {},\n \"status\": \"<string>\"\n }\n ]\n}"
},
{
"name": "Error",
"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 \"trigger_category\": {\n \"name\": \"<string>\",\n \"position\": \"<long>\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/trigger_categories",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"trigger_categories"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n {\n \"code\": \"<string>\",\n \"title\": \"<string>\",\n \"detail\": \"<string>\",\n \"id\": \"<string>\",\n \"links\": {},\n \"source\": {},\n \"status\": \"<string>\"\n },\n {\n \"code\": \"<string>\",\n \"title\": \"<string>\",\n \"detail\": \"<string>\",\n \"id\": \"<string>\",\n \"links\": {},\n \"source\": {},\n \"status\": \"<string>\"\n }\n ]\n}"
}
]
}