Chilkat Online Tools

SQL Server / Support API / List Ticket Metrics

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', 'login'
    EXEC sp_OASetProperty @http, 'Password', 'password'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @sbResponseBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://example.zendesk.com/api/v2/ticket_metrics', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    DECLARE @Business nvarchar(4000)

    DECLARE @Calendar nvarchar(4000)

    DECLARE @assigned_at nvarchar(4000)

    DECLARE @assignee_stations nvarchar(4000)

    DECLARE @assignee_updated_at nvarchar(4000)

    DECLARE @created_at nvarchar(4000)

    DECLARE @custom_status_updated_at nvarchar(4000)

    DECLARE @first_resolution_time_in_minutesBusiness nvarchar(4000)

    DECLARE @first_resolution_time_in_minutesCalendar nvarchar(4000)

    DECLARE @full_resolution_time_in_minutesBusiness nvarchar(4000)

    DECLARE @full_resolution_time_in_minutesCalendar nvarchar(4000)

    DECLARE @group_stations nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @initially_assigned_at nvarchar(4000)

    DECLARE @latest_comment_added_at nvarchar(4000)

    DECLARE @on_hold_time_in_minutesBusiness nvarchar(4000)

    DECLARE @on_hold_time_in_minutesCalendar nvarchar(4000)

    DECLARE @reopens nvarchar(4000)

    DECLARE @replies nvarchar(4000)

    DECLARE @reply_time_in_minutesBusiness nvarchar(4000)

    DECLARE @reply_time_in_minutesCalendar nvarchar(4000)

    DECLARE @reply_time_in_secondsBusiness nvarchar(4000)

    DECLARE @reply_time_in_secondsCalendar nvarchar(4000)

    DECLARE @requester_updated_at nvarchar(4000)

    DECLARE @requester_wait_time_in_minutesBusiness nvarchar(4000)

    DECLARE @requester_wait_time_in_minutesCalendar nvarchar(4000)

    DECLARE @solved_at nvarchar(4000)

    DECLARE @status_updated_at nvarchar(4000)

    DECLARE @ticket_id nvarchar(4000)

    DECLARE @updated_at nvarchar(4000)

    DECLARE @url nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'ticket_metrics'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @Business OUT, 'ticket_metrics[i].agent_wait_time_in_minutes.business'
        EXEC sp_OAMethod @jResp, 'StringOf', @Calendar OUT, 'ticket_metrics[i].agent_wait_time_in_minutes.calendar'
        EXEC sp_OAMethod @jResp, 'StringOf', @assigned_at OUT, 'ticket_metrics[i].assigned_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @assignee_stations OUT, 'ticket_metrics[i].assignee_stations'
        EXEC sp_OAMethod @jResp, 'StringOf', @assignee_updated_at OUT, 'ticket_metrics[i].assignee_updated_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'ticket_metrics[i].created_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @custom_status_updated_at OUT, 'ticket_metrics[i].custom_status_updated_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @first_resolution_time_in_minutesBusiness OUT, 'ticket_metrics[i].first_resolution_time_in_minutes.business'
        EXEC sp_OAMethod @jResp, 'StringOf', @first_resolution_time_in_minutesCalendar OUT, 'ticket_metrics[i].first_resolution_time_in_minutes.calendar'
        EXEC sp_OAMethod @jResp, 'StringOf', @full_resolution_time_in_minutesBusiness OUT, 'ticket_metrics[i].full_resolution_time_in_minutes.business'
        EXEC sp_OAMethod @jResp, 'StringOf', @full_resolution_time_in_minutesCalendar OUT, 'ticket_metrics[i].full_resolution_time_in_minutes.calendar'
        EXEC sp_OAMethod @jResp, 'StringOf', @group_stations OUT, 'ticket_metrics[i].group_stations'
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'ticket_metrics[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @initially_assigned_at OUT, 'ticket_metrics[i].initially_assigned_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @latest_comment_added_at OUT, 'ticket_metrics[i].latest_comment_added_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @on_hold_time_in_minutesBusiness OUT, 'ticket_metrics[i].on_hold_time_in_minutes.business'
        EXEC sp_OAMethod @jResp, 'StringOf', @on_hold_time_in_minutesCalendar OUT, 'ticket_metrics[i].on_hold_time_in_minutes.calendar'
        EXEC sp_OAMethod @jResp, 'StringOf', @reopens OUT, 'ticket_metrics[i].reopens'
        EXEC sp_OAMethod @jResp, 'StringOf', @replies OUT, 'ticket_metrics[i].replies'
        EXEC sp_OAMethod @jResp, 'StringOf', @reply_time_in_minutesBusiness OUT, 'ticket_metrics[i].reply_time_in_minutes.business'
        EXEC sp_OAMethod @jResp, 'StringOf', @reply_time_in_minutesCalendar OUT, 'ticket_metrics[i].reply_time_in_minutes.calendar'
        EXEC sp_OAMethod @jResp, 'StringOf', @reply_time_in_secondsBusiness OUT, 'ticket_metrics[i].reply_time_in_seconds.business'
        EXEC sp_OAMethod @jResp, 'StringOf', @reply_time_in_secondsCalendar OUT, 'ticket_metrics[i].reply_time_in_seconds.calendar'
        EXEC sp_OAMethod @jResp, 'StringOf', @requester_updated_at OUT, 'ticket_metrics[i].requester_updated_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @requester_wait_time_in_minutesBusiness OUT, 'ticket_metrics[i].requester_wait_time_in_minutes.business'
        EXEC sp_OAMethod @jResp, 'StringOf', @requester_wait_time_in_minutesCalendar OUT, 'ticket_metrics[i].requester_wait_time_in_minutes.calendar'
        EXEC sp_OAMethod @jResp, 'StringOf', @solved_at OUT, 'ticket_metrics[i].solved_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @status_updated_at OUT, 'ticket_metrics[i].status_updated_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @ticket_id OUT, 'ticket_metrics[i].ticket_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'ticket_metrics[i].updated_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'ticket_metrics[i].url'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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