DataFlex / Support API / Create Batch Job for Trigger Categories
Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sCode
String sTitle
String sDetail
String sId
String sTrigger_id
String sCreated_at
String sName
String sPosition
String sUpdated_at
String sActive
String sCategory_id
String sDefault
String sDescription
String sRaw_title
String sUrl
Integer j
Integer iCount_j
String sField
String sOperator
String sValue
String sStatus
Integer i
Integer iCount_i
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComBasicAuth Of hoHttp To True
Set ComLogin Of hoHttp To "login"
Set ComPassword Of hoHttp To "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.
// {
// "job": {
// "action": "patch",
// "items": {
// "trigger_categories": [
// {
// "id": "<string>",
// "position": "<long>"
// },
// {
// "id": "<string>",
// "position": "<long>"
// }
// ],
// "triggers": [
// {
// "id": "<string>",
// "active": "<boolean>",
// "category_id": "<string>",
// "position": "<long>"
// },
// {
// "id": "<string>",
// "active": "<boolean>",
// "category_id": "<string>",
// "position": "<long>"
// }
// ]
// }
// }
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "job.action" "patch" To iSuccess
Get ComUpdateString Of hoJson "job.items.trigger_categories[0].id" "<string>" To iSuccess
Get ComUpdateString Of hoJson "job.items.trigger_categories[0].position" "<long>" To iSuccess
Get ComUpdateString Of hoJson "job.items.trigger_categories[1].id" "<string>" To iSuccess
Get ComUpdateString Of hoJson "job.items.trigger_categories[1].position" "<long>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[0].id" "<string>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[0].active" "<boolean>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[0].category_id" "<string>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[0].position" "<long>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[1].id" "<string>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[1].active" "<boolean>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[1].category_id" "<string>" To iSuccess
Get ComUpdateString Of hoJson "job.items.triggers[1].position" "<long>" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Send ComSetRequestHeader To hoHttp "Accept" "application/json"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://example.zendesk.com/api/v2/trigger_categories/jobs" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "errors": [
// {
// "code": "<string>",
// "title": "<string>",
// "detail": "<string>",
// "id": "<string>",
// "links": {},
// "source": {},
// "status": "<string>",
// "trigger_id": "<string>"
// },
// {
// "code": "<string>",
// "title": "<string>",
// "detail": "<string>",
// "id": "<string>",
// "links": {},
// "source": {},
// "status": "<string>",
// "trigger_id": "<string>"
// }
// ],
// "results": {
// "trigger_categories": [
// {
// "created_at": "<string>",
// "id": "<string>",
// "name": "<string>",
// "position": "<long>",
// "updated_at": "<string>"
// },
// {
// "created_at": "<string>",
// "id": "<string>",
// "name": "<string>",
// "position": "<long>",
// "updated_at": "<string>"
// }
// ],
// "triggers": [
// {
// "conditions": {
// "all": [
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// }
// ],
// "any": [
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// }
// ]
// },
// "actions": [
// {
// "field": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "value": "<string>"
// }
// ],
// "title": "<string>",
// "active": "<boolean>",
// "category_id": "<string>",
// "created_at": "<string>",
// "default": "<boolean>",
// "description": "<string>",
// "id": "<integer>",
// "position": "<integer>",
// "raw_title": "<string>",
// "updated_at": "<string>",
// "url": "<string>"
// },
// {
// "conditions": {
// "all": [
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// }
// ],
// "any": [
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// }
// ]
// },
// "actions": [
// {
// "field": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "value": "<string>"
// }
// ],
// "title": "<string>",
// "active": "<boolean>",
// "category_id": "<string>",
// "created_at": "<string>",
// "default": "<boolean>",
// "description": "<string>",
// "id": "<integer>",
// "position": "<integer>",
// "raw_title": "<string>",
// "updated_at": "<string>",
// "url": "<string>"
// }
// ]
// },
// "status": "failed"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Get ComStringOf Of hoJResp "status" To sStatus
Move 0 To i
Get ComSizeOfArray Of hoJResp "errors" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "errors[i].code" To sCode
Get ComStringOf Of hoJResp "errors[i].title" To sTitle
Get ComStringOf Of hoJResp "errors[i].detail" To sDetail
Get ComStringOf Of hoJResp "errors[i].id" To sId
Get ComStringOf Of hoJResp "errors[i].status" To sStatus
Get ComStringOf Of hoJResp "errors[i].trigger_id" To sTrigger_id
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "results.trigger_categories" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "results.trigger_categories[i].created_at" To sCreated_at
Get ComStringOf Of hoJResp "results.trigger_categories[i].id" To sId
Get ComStringOf Of hoJResp "results.trigger_categories[i].name" To sName
Get ComStringOf Of hoJResp "results.trigger_categories[i].position" To sPosition
Get ComStringOf Of hoJResp "results.trigger_categories[i].updated_at" To sUpdated_at
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "results.triggers" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "results.triggers[i].title" To sTitle
Get ComStringOf Of hoJResp "results.triggers[i].active" To sActive
Get ComStringOf Of hoJResp "results.triggers[i].category_id" To sCategory_id
Get ComStringOf Of hoJResp "results.triggers[i].created_at" To sCreated_at
Get ComStringOf Of hoJResp "results.triggers[i].default" To sDefault
Get ComStringOf Of hoJResp "results.triggers[i].description" To sDescription
Get ComStringOf Of hoJResp "results.triggers[i].id" To sId
Get ComStringOf Of hoJResp "results.triggers[i].position" To sPosition
Get ComStringOf Of hoJResp "results.triggers[i].raw_title" To sRaw_title
Get ComStringOf Of hoJResp "results.triggers[i].updated_at" To sUpdated_at
Get ComStringOf Of hoJResp "results.triggers[i].url" To sUrl
Move 0 To j
Get ComSizeOfArray Of hoJResp "results.triggers[i].conditions.all" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "results.triggers[i].conditions.all[j].field" To sField
Get ComStringOf Of hoJResp "results.triggers[i].conditions.all[j].operator" To sOperator
Get ComStringOf Of hoJResp "results.triggers[i].conditions.all[j].value" To sValue
Move (j + 1) To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJResp "results.triggers[i].conditions.any" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "results.triggers[i].conditions.any[j].field" To sField
Get ComStringOf Of hoJResp "results.triggers[i].conditions.any[j].operator" To sOperator
Get ComStringOf Of hoJResp "results.triggers[i].conditions.any[j].value" To sValue
Move (j + 1) To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJResp "results.triggers[i].actions" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "results.triggers[i].actions[j].field" To sField
Get ComStringOf Of hoJResp "results.triggers[i].actions[j].value" To sValue
Move (j + 1) To j
Loop
Move (i + 1) To i
Loop
End_Procedure
Curl Command
curl -u login:password -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"job": {
"action": "patch",
"items": {
"trigger_categories": [
{
"id": "<string>",
"position": "<long>"
},
{
"id": "<string>",
"position": "<long>"
}
],
"triggers": [
{
"id": "<string>",
"active": "<boolean>",
"category_id": "<string>",
"position": "<long>"
},
{
"id": "<string>",
"active": "<boolean>",
"category_id": "<string>",
"position": "<long>"
}
]
}
}
}'
https://example.zendesk.com/api/v2/trigger_categories/jobs
Postman Collection Item JSON
{
"name": "Create Batch Job for Trigger Categories",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"job\": {\n \"action\": \"patch\",\n \"items\": {\n \"trigger_categories\": [\n {\n \"id\": \"<string>\",\n \"position\": \"<long>\"\n },\n {\n \"id\": \"<string>\",\n \"position\": \"<long>\"\n }\n ],\n \"triggers\": [\n {\n \"id\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"position\": \"<long>\"\n },\n {\n \"id\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"position\": \"<long>\"\n }\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/trigger_categories/jobs",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"trigger_categories",
"jobs"
]
},
"description": "Creates a job that performs a batch operation for the given trigger categories."
},
"response": [
{
"name": "The response to the batch job",
"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 \"job\": {\n \"action\": \"patch\",\n \"items\": {\n \"trigger_categories\": [\n {\n \"id\": \"<string>\",\n \"position\": \"<long>\"\n },\n {\n \"id\": \"<string>\",\n \"position\": \"<long>\"\n }\n ],\n \"triggers\": [\n {\n \"id\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"position\": \"<long>\"\n },\n {\n \"id\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"position\": \"<long>\"\n }\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/trigger_categories/jobs",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"trigger_categories",
"jobs"
]
}
},
"status": "OK",
"code": 200,
"_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 \"trigger_id\": \"<string>\"\n },\n {\n \"code\": \"<string>\",\n \"title\": \"<string>\",\n \"detail\": \"<string>\",\n \"id\": \"<string>\",\n \"links\": {},\n \"source\": {},\n \"status\": \"<string>\",\n \"trigger_id\": \"<string>\"\n }\n ],\n \"results\": {\n \"trigger_categories\": [\n {\n \"created_at\": \"<string>\",\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"position\": \"<long>\",\n \"updated_at\": \"<string>\"\n },\n {\n \"created_at\": \"<string>\",\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"position\": \"<long>\",\n \"updated_at\": \"<string>\"\n }\n ],\n \"triggers\": [\n {\n \"conditions\": {\n \"all\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"any\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n },\n \"actions\": [\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"title\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"created_at\": \"<string>\",\n \"default\": \"<boolean>\",\n \"description\": \"<string>\",\n \"id\": \"<integer>\",\n \"position\": \"<integer>\",\n \"raw_title\": \"<string>\",\n \"updated_at\": \"<string>\",\n \"url\": \"<string>\"\n },\n {\n \"conditions\": {\n \"all\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"any\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n },\n \"actions\": [\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"title\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"created_at\": \"<string>\",\n \"default\": \"<boolean>\",\n \"description\": \"<string>\",\n \"id\": \"<integer>\",\n \"position\": \"<integer>\",\n \"raw_title\": \"<string>\",\n \"updated_at\": \"<string>\",\n \"url\": \"<string>\"\n }\n ]\n },\n \"status\": \"failed\"\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 \"job\": {\n \"action\": \"patch\",\n \"items\": {\n \"trigger_categories\": [\n {\n \"id\": \"<string>\",\n \"position\": \"<long>\"\n },\n {\n \"id\": \"<string>\",\n \"position\": \"<long>\"\n }\n ],\n \"triggers\": [\n {\n \"id\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"position\": \"<long>\"\n },\n {\n \"id\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"position\": \"<long>\"\n }\n ]\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/trigger_categories/jobs",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"trigger_categories",
"jobs"
]
}
},
"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 \"trigger_id\": \"<string>\"\n },\n {\n \"code\": \"<string>\",\n \"title\": \"<string>\",\n \"detail\": \"<string>\",\n \"id\": \"<string>\",\n \"links\": {},\n \"source\": {},\n \"status\": \"<string>\",\n \"trigger_id\": \"<string>\"\n }\n ],\n \"results\": {\n \"trigger_categories\": [\n {\n \"created_at\": \"<string>\",\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"position\": \"<long>\",\n \"updated_at\": \"<string>\"\n },\n {\n \"created_at\": \"<string>\",\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"position\": \"<long>\",\n \"updated_at\": \"<string>\"\n }\n ],\n \"triggers\": [\n {\n \"conditions\": {\n \"all\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"any\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n },\n \"actions\": [\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"title\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"created_at\": \"<string>\",\n \"default\": \"<boolean>\",\n \"description\": \"<string>\",\n \"id\": \"<integer>\",\n \"position\": \"<integer>\",\n \"raw_title\": \"<string>\",\n \"updated_at\": \"<string>\",\n \"url\": \"<string>\"\n },\n {\n \"conditions\": {\n \"all\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"any\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n },\n \"actions\": [\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"title\": \"<string>\",\n \"active\": \"<boolean>\",\n \"category_id\": \"<string>\",\n \"created_at\": \"<string>\",\n \"default\": \"<boolean>\",\n \"description\": \"<string>\",\n \"id\": \"<integer>\",\n \"position\": \"<integer>\",\n \"raw_title\": \"<string>\",\n \"updated_at\": \"<string>\",\n \"url\": \"<string>\"\n }\n ]\n },\n \"status\": \"failed\"\n}"
}
]
}