Chilkat Online Tools

SQL Server / Support API / List Ticket Metric Events

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
    DECLARE @iTmp0 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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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'

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'start_time', '<integer>'

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

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://example.zendesk.com/api/v2/incremental/ticket_metric_events', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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 @resp, 'StatusCode', @respStatusCode OUT

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

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @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

    DECLARE @id nvarchar(4000)

    DECLARE @instance_id nvarchar(4000)

    DECLARE @metric nvarchar(4000)

    DECLARE @ticket_id nvarchar(4000)

    DECLARE @time nvarchar(4000)

    DECLARE @v_type nvarchar(4000)

    DECLARE @count nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @count OUT, 'count'
    DECLARE @end_time nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @end_time OUT, 'end_time'
    DECLARE @next_page nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @next_page OUT, 'next_page'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'ticket_metric_events'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'ticket_metric_events[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @instance_id OUT, 'ticket_metric_events[i].instance_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @metric OUT, 'ticket_metric_events[i].metric'
        EXEC sp_OAMethod @jResp, 'StringOf', @ticket_id OUT, 'ticket_metric_events[i].ticket_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @time OUT, 'ticket_metric_events[i].time'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'ticket_metric_events[i].type'
        SELECT @i = @i + 1
      END

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


END
GO

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