Chilkat Online Tools

PureBasic / Support API / List Ticket Metric Events

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")

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"start_time","<integer>")

    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://example.zendesk.com/api/v2/incremental/ticket_metric_events",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        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(queryParams)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

    ; Sample JSON response:
    ; (Sample code for parsing the JSON response is shown below)

    ; {
    ;   "ticket_metric_events": [
    ;     {
    ;       "id": "<integer>",
    ;       "instance_id": "<integer>",
    ;       "metric": "agent_work_time",
    ;       "ticket_id": "<integer>",
    ;       "time": "<dateTime>",
    ;       "type": "apply_sla"
    ;     },
    ;     {
    ;       "id": "<integer>",
    ;       "instance_id": "<integer>",
    ;       "metric": "pausable_update_time",
    ;       "ticket_id": "<integer>",
    ;       "time": "<dateTime>",
    ;       "type": "pause"
    ;     }
    ;   ],
    ;   "count": "<integer>",
    ;   "end_time": "<integer>",
    ;   "next_page": "<string>"
    ; }

    ; Sample code for parsing the JSON response...
    ; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    id.s
    instance_id.s
    metric.s
    ticket_id.s
    time.s
    v_type.s

    count.s = CkJsonObject::ckStringOf(jResp,"count")
    end_time.s = CkJsonObject::ckStringOf(jResp,"end_time")
    next_page.s = CkJsonObject::ckStringOf(jResp,"next_page")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"ticket_metric_events")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        id = CkJsonObject::ckStringOf(jResp,"ticket_metric_events[i].id")
        instance_id = CkJsonObject::ckStringOf(jResp,"ticket_metric_events[i].instance_id")
        metric = CkJsonObject::ckStringOf(jResp,"ticket_metric_events[i].metric")
        ticket_id = CkJsonObject::ckStringOf(jResp,"ticket_metric_events[i].ticket_id")
        time = CkJsonObject::ckStringOf(jResp,"ticket_metric_events[i].time")
        v_type = CkJsonObject::ckStringOf(jResp,"ticket_metric_events[i].type")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl  -u login:password -G -d "start_time=%3Cinteger%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/incremental/ticket_metric_events

Postman Collection Item JSON

{
  "name": "List Ticket Metric Events",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/incremental/ticket_metric_events?start_time=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "incremental",
        "ticket_metric_events"
      ],
      "query": [
        {
          "key": "start_time",
          "value": "<integer>",
          "description": "(Required) The Unix UTC epoch time of the oldest event you're interested in. Example: 1332034771."
        }
      ]
    },
    "description": "Returns ticket metric events that occurred on or after the start time.\n\nCursor pagination returns a maximum of 100 records per page. Events are listed in chronological order.\n\nIf the results are not paginated, events will be returned as a time-based incremental export.\n\nSee [Time-based incremental exports](/documentation/ticketing/managing-tickets/using-the-incremental-export-api#time-based-incremental-exports).\n\n#### Pagination\n* Cursor pagination\n* No pagination\n\nSee [Pagination](/api-reference/introduction/pagination/).\n\n#### Allowed For\n\n* Admins"
  },
  "response": [
    {
      "name": "Successful response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/incremental/ticket_metric_events?start_time=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "incremental",
            "ticket_metric_events"
          ],
          "query": [
            {
              "key": "start_time",
              "value": "<integer>",
              "description": "(Required) The Unix UTC epoch time of the oldest event you're interested in. Example: 1332034771."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"ticket_metric_events\": [\n    {\n      \"id\": \"<integer>\",\n      \"instance_id\": \"<integer>\",\n      \"metric\": \"agent_work_time\",\n      \"ticket_id\": \"<integer>\",\n      \"time\": \"<dateTime>\",\n      \"type\": \"apply_sla\"\n    },\n    {\n      \"id\": \"<integer>\",\n      \"instance_id\": \"<integer>\",\n      \"metric\": \"pausable_update_time\",\n      \"ticket_id\": \"<integer>\",\n      \"time\": \"<dateTime>\",\n      \"type\": \"pause\"\n    }\n  ],\n  \"count\": \"<integer>\",\n  \"end_time\": \"<integer>\",\n  \"next_page\": \"<string>\"\n}"
    }
  ]
}