Chilkat Online Tools

autoit / Support API / Create Batch Job for Trigger Categories

Back to Collection Items

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat_9_5_0.Http")
Local $bSuccess

$oHttp.BasicAuth = True
$oHttp.Login = "login"
$oHttp.Password = "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>"
;         }
;       ]
;     }
;   }
; }

$oJson = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJson.UpdateString("job.action","patch")
$oJson.UpdateString("job.items.trigger_categories[0].id","<string>")
$oJson.UpdateString("job.items.trigger_categories[0].position","<long>")
$oJson.UpdateString("job.items.trigger_categories[1].id","<string>")
$oJson.UpdateString("job.items.trigger_categories[1].position","<long>")
$oJson.UpdateString("job.items.triggers[0].id","<string>")
$oJson.UpdateString("job.items.triggers[0].active","<boolean>")
$oJson.UpdateString("job.items.triggers[0].category_id","<string>")
$oJson.UpdateString("job.items.triggers[0].position","<long>")
$oJson.UpdateString("job.items.triggers[1].id","<string>")
$oJson.UpdateString("job.items.triggers[1].active","<boolean>")
$oJson.UpdateString("job.items.triggers[1].category_id","<string>")
$oJson.UpdateString("job.items.triggers[1].position","<long>")

$oHttp.SetRequestHeader "Content-Type","application/json"
$oHttp.SetRequestHeader "Accept","application/json"

Local $oResp = $oHttp.PostJson3("https://example.zendesk.com/api/v2/trigger_categories/jobs","application/json",$oJson)
If ($oHttp.LastMethodSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)

$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)

    Exit
EndIf

; 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

Local $sCode
Local $sTitle
Local $sDetail
Local $sId
Local $sTrigger_id
Local $sCreated_at
Local $sName
Local $sPosition
Local $sUpdated_at
Local $sActive
Local $sCategory_id
Local $sDefault
Local $sDescription
Local $sRaw_title
Local $sUrl
Local $iJ
Local $iCount_j
Local $sField
Local $sOperator
Local $sValue

Local $status = $oJResp.StringOf("status")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("errors")
While $i < $iCount_i
    $oJResp.I = $i
    $sCode = $oJResp.StringOf("errors[i].code")
    $sTitle = $oJResp.StringOf("errors[i].title")
    $sDetail = $oJResp.StringOf("errors[i].detail")
    $sId = $oJResp.StringOf("errors[i].id")
    $status = $oJResp.StringOf("errors[i].status")
    $sTrigger_id = $oJResp.StringOf("errors[i].trigger_id")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("results.trigger_categories")
While $i < $iCount_i
    $oJResp.I = $i
    $sCreated_at = $oJResp.StringOf("results.trigger_categories[i].created_at")
    $sId = $oJResp.StringOf("results.trigger_categories[i].id")
    $sName = $oJResp.StringOf("results.trigger_categories[i].name")
    $sPosition = $oJResp.StringOf("results.trigger_categories[i].position")
    $sUpdated_at = $oJResp.StringOf("results.trigger_categories[i].updated_at")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("results.triggers")
While $i < $iCount_i
    $oJResp.I = $i
    $sTitle = $oJResp.StringOf("results.triggers[i].title")
    $sActive = $oJResp.StringOf("results.triggers[i].active")
    $sCategory_id = $oJResp.StringOf("results.triggers[i].category_id")
    $sCreated_at = $oJResp.StringOf("results.triggers[i].created_at")
    $sDefault = $oJResp.StringOf("results.triggers[i].default")
    $sDescription = $oJResp.StringOf("results.triggers[i].description")
    $sId = $oJResp.StringOf("results.triggers[i].id")
    $sPosition = $oJResp.StringOf("results.triggers[i].position")
    $sRaw_title = $oJResp.StringOf("results.triggers[i].raw_title")
    $sUpdated_at = $oJResp.StringOf("results.triggers[i].updated_at")
    $sUrl = $oJResp.StringOf("results.triggers[i].url")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("results.triggers[i].conditions.all")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sField = $oJResp.StringOf("results.triggers[i].conditions.all[j].field")
        $sOperator = $oJResp.StringOf("results.triggers[i].conditions.all[j].operator")
        $sValue = $oJResp.StringOf("results.triggers[i].conditions.all[j].value")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("results.triggers[i].conditions.any")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sField = $oJResp.StringOf("results.triggers[i].conditions.any[j].field")
        $sOperator = $oJResp.StringOf("results.triggers[i].conditions.any[j].operator")
        $sValue = $oJResp.StringOf("results.triggers[i].conditions.any[j].value")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("results.triggers[i].actions")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sField = $oJResp.StringOf("results.triggers[i].actions[j].field")
        $sValue = $oJResp.StringOf("results.triggers[i].actions[j].value")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

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}"
    }
  ]
}