Chilkat Online Tools

C / Support API / List Ticket Metrics

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *Business;
    const char *Calendar;
    const char *assigned_at;
    const char *assignee_stations;
    const char *assignee_updated_at;
    const char *created_at;
    const char *custom_status_updated_at;
    const char *first_resolution_time_in_minutesBusiness;
    const char *first_resolution_time_in_minutesCalendar;
    const char *full_resolution_time_in_minutesBusiness;
    const char *full_resolution_time_in_minutesCalendar;
    const char *group_stations;
    const char *id;
    const char *initially_assigned_at;
    const char *latest_comment_added_at;
    const char *on_hold_time_in_minutesBusiness;
    const char *on_hold_time_in_minutesCalendar;
    const char *reopens;
    const char *replies;
    const char *reply_time_in_minutesBusiness;
    const char *reply_time_in_minutesCalendar;
    const char *reply_time_in_secondsBusiness;
    const char *reply_time_in_secondsCalendar;
    const char *requester_updated_at;
    const char *requester_wait_time_in_minutesBusiness;
    const char *requester_wait_time_in_minutesCalendar;
    const char *solved_at;
    const char *status_updated_at;
    const char *ticket_id;
    const char *updated_at;
    const char *url;
    int i;
    int count_i;

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

    http = CkHttp_Create();

    CkHttp_putBasicAuth(http,TRUE);
    CkHttp_putLogin(http,"login");
    CkHttp_putPassword(http,"password");

    CkHttp_SetRequestHeader(http,"Accept","application/json");

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://example.zendesk.com/api/v2/ticket_metrics",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttp_getLastStatus(http);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttp_lastHeader(http));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

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

    // {
    //   "ticket_metrics": [
    //     {
    //       "agent_wait_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "assigned_at": "<dateTime>",
    //       "assignee_stations": "<integer>",
    //       "assignee_updated_at": "<dateTime>",
    //       "created_at": "<dateTime>",
    //       "custom_status_updated_at": "<dateTime>",
    //       "first_resolution_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "full_resolution_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "group_stations": "<integer>",
    //       "id": "<integer>",
    //       "initially_assigned_at": "<dateTime>",
    //       "latest_comment_added_at": "<dateTime>",
    //       "on_hold_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "reopens": "<integer>",
    //       "replies": "<integer>",
    //       "reply_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "reply_time_in_seconds": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "requester_updated_at": "<dateTime>",
    //       "requester_wait_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "solved_at": "<dateTime>",
    //       "status_updated_at": "<dateTime>",
    //       "ticket_id": "<integer>",
    //       "updated_at": "<dateTime>",
    //       "url": "<string>"
    //     },
    //     {
    //       "agent_wait_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "assigned_at": "<dateTime>",
    //       "assignee_stations": "<integer>",
    //       "assignee_updated_at": "<dateTime>",
    //       "created_at": "<dateTime>",
    //       "custom_status_updated_at": "<dateTime>",
    //       "first_resolution_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "full_resolution_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "group_stations": "<integer>",
    //       "id": "<integer>",
    //       "initially_assigned_at": "<dateTime>",
    //       "latest_comment_added_at": "<dateTime>",
    //       "on_hold_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "reopens": "<integer>",
    //       "replies": "<integer>",
    //       "reply_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "reply_time_in_seconds": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "requester_updated_at": "<dateTime>",
    //       "requester_wait_time_in_minutes": {
    //         "business": "<integer>",
    //         "calendar": "<integer>"
    //       },
    //       "solved_at": "<dateTime>",
    //       "status_updated_at": "<dateTime>",
    //       "ticket_id": "<integer>",
    //       "updated_at": "<dateTime>",
    //       "url": "<string>"
    //     }
    //   ]
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"ticket_metrics");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        Business = CkJsonObject_stringOf(jResp,"ticket_metrics[i].agent_wait_time_in_minutes.business");
        Calendar = CkJsonObject_stringOf(jResp,"ticket_metrics[i].agent_wait_time_in_minutes.calendar");
        assigned_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].assigned_at");
        assignee_stations = CkJsonObject_stringOf(jResp,"ticket_metrics[i].assignee_stations");
        assignee_updated_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].assignee_updated_at");
        created_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].created_at");
        custom_status_updated_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].custom_status_updated_at");
        first_resolution_time_in_minutesBusiness = CkJsonObject_stringOf(jResp,"ticket_metrics[i].first_resolution_time_in_minutes.business");
        first_resolution_time_in_minutesCalendar = CkJsonObject_stringOf(jResp,"ticket_metrics[i].first_resolution_time_in_minutes.calendar");
        full_resolution_time_in_minutesBusiness = CkJsonObject_stringOf(jResp,"ticket_metrics[i].full_resolution_time_in_minutes.business");
        full_resolution_time_in_minutesCalendar = CkJsonObject_stringOf(jResp,"ticket_metrics[i].full_resolution_time_in_minutes.calendar");
        group_stations = CkJsonObject_stringOf(jResp,"ticket_metrics[i].group_stations");
        id = CkJsonObject_stringOf(jResp,"ticket_metrics[i].id");
        initially_assigned_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].initially_assigned_at");
        latest_comment_added_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].latest_comment_added_at");
        on_hold_time_in_minutesBusiness = CkJsonObject_stringOf(jResp,"ticket_metrics[i].on_hold_time_in_minutes.business");
        on_hold_time_in_minutesCalendar = CkJsonObject_stringOf(jResp,"ticket_metrics[i].on_hold_time_in_minutes.calendar");
        reopens = CkJsonObject_stringOf(jResp,"ticket_metrics[i].reopens");
        replies = CkJsonObject_stringOf(jResp,"ticket_metrics[i].replies");
        reply_time_in_minutesBusiness = CkJsonObject_stringOf(jResp,"ticket_metrics[i].reply_time_in_minutes.business");
        reply_time_in_minutesCalendar = CkJsonObject_stringOf(jResp,"ticket_metrics[i].reply_time_in_minutes.calendar");
        reply_time_in_secondsBusiness = CkJsonObject_stringOf(jResp,"ticket_metrics[i].reply_time_in_seconds.business");
        reply_time_in_secondsCalendar = CkJsonObject_stringOf(jResp,"ticket_metrics[i].reply_time_in_seconds.calendar");
        requester_updated_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].requester_updated_at");
        requester_wait_time_in_minutesBusiness = CkJsonObject_stringOf(jResp,"ticket_metrics[i].requester_wait_time_in_minutes.business");
        requester_wait_time_in_minutesCalendar = CkJsonObject_stringOf(jResp,"ticket_metrics[i].requester_wait_time_in_minutes.calendar");
        solved_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].solved_at");
        status_updated_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].status_updated_at");
        ticket_id = CkJsonObject_stringOf(jResp,"ticket_metrics[i].ticket_id");
        updated_at = CkJsonObject_stringOf(jResp,"ticket_metrics[i].updated_at");
        url = CkJsonObject_stringOf(jResp,"ticket_metrics[i].url");
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl  -u login:password -X GET
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/ticket_metrics

Postman Collection Item JSON

{
  "name": "List Ticket Metrics",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/ticket_metrics",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "ticket_metrics"
      ]
    },
    "description": "Returns a list of tickets with their metrics.\n\nTickets are ordered chronologically by created date, from newest to oldest.\nThe last ticket listed may not be the absolute oldest ticket in your account\ndue to ticket archiving.\n\nArchived tickets are not included in the response. See\n[About archived tickets](https://support.zendesk.com/hc/en-us/articles/203657756) in\nZendesk help.\n\n#### Pagination\n\n- Cursor pagination (recommended)\n- Offset pagination\n\nSee [Pagination](/api-reference/introduction/pagination/).\n\nReturns a maximum of 100 records per page.\n\n\n#### Allowed For\n\n* Agents\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/ticket_metrics",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "ticket_metrics"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"ticket_metrics\": [\n    {\n      \"agent_wait_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"assigned_at\": \"<dateTime>\",\n      \"assignee_stations\": \"<integer>\",\n      \"assignee_updated_at\": \"<dateTime>\",\n      \"created_at\": \"<dateTime>\",\n      \"custom_status_updated_at\": \"<dateTime>\",\n      \"first_resolution_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"full_resolution_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"group_stations\": \"<integer>\",\n      \"id\": \"<integer>\",\n      \"initially_assigned_at\": \"<dateTime>\",\n      \"latest_comment_added_at\": \"<dateTime>\",\n      \"on_hold_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"reopens\": \"<integer>\",\n      \"replies\": \"<integer>\",\n      \"reply_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"reply_time_in_seconds\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"requester_updated_at\": \"<dateTime>\",\n      \"requester_wait_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"solved_at\": \"<dateTime>\",\n      \"status_updated_at\": \"<dateTime>\",\n      \"ticket_id\": \"<integer>\",\n      \"updated_at\": \"<dateTime>\",\n      \"url\": \"<string>\"\n    },\n    {\n      \"agent_wait_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"assigned_at\": \"<dateTime>\",\n      \"assignee_stations\": \"<integer>\",\n      \"assignee_updated_at\": \"<dateTime>\",\n      \"created_at\": \"<dateTime>\",\n      \"custom_status_updated_at\": \"<dateTime>\",\n      \"first_resolution_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"full_resolution_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"group_stations\": \"<integer>\",\n      \"id\": \"<integer>\",\n      \"initially_assigned_at\": \"<dateTime>\",\n      \"latest_comment_added_at\": \"<dateTime>\",\n      \"on_hold_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"reopens\": \"<integer>\",\n      \"replies\": \"<integer>\",\n      \"reply_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"reply_time_in_seconds\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"requester_updated_at\": \"<dateTime>\",\n      \"requester_wait_time_in_minutes\": {\n        \"business\": \"<integer>\",\n        \"calendar\": \"<integer>\"\n      },\n      \"solved_at\": \"<dateTime>\",\n      \"status_updated_at\": \"<dateTime>\",\n      \"ticket_id\": \"<integer>\",\n      \"updated_at\": \"<dateTime>\",\n      \"url\": \"<string>\"\n    }\n  ]\n}"
    }
  ]
}