Chilkat Online Tools

SQL Server / Support API / List Audits for a Ticket

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/tickets/:ticket_id/audits', @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)

    -- {
    --   "audits": [
    --     {
    --       "author_id": "<integer>",
    --       "created_at": "<dateTime>",
    --       "events": [
    --         {
    --           "in14": 98255426.2140105,
    --           "consequat_b9": false,
    --           "Lorem4": -18718960,
    --           "incididunt_a": 91476803.94307658
    --         },
    --         {
    --           "ipsume1": -99329065,
    --           "laboris_8c": 89859673.3933256,
    --           "consectetur6": true
    --         }
    --       ],
    --       "id": "<integer>",
    --       "metadata": {
    --         "fugiat2_": 32930402.342455566,
    --         "aliqua4f": false
    --       },
    --       "ticket_id": "<integer>",
    --       "via": {
    --         "channel": "<string>",
    --         "source": {
    --           "amet29d": "veniam",
    --           "aliqua_b0": -53884767.66002053,
    --           "amet_24": 77146472.24303994,
    --           "non_b8": 30237848
    --         }
    --       }
    --     },
    --     {
    --       "author_id": "<integer>",
    --       "created_at": "<dateTime>",
    --       "events": [
    --         {
    --           "officia1": true
    --         },
    --         {
    --           "minim_27": true,
    --           "Ut7_2": -37549201.88334068
    --         }
    --       ],
    --       "id": "<integer>",
    --       "metadata": {
    --         "in_3a": 96878618,
    --         "occaecat_d98": 24309571
    --       },
    --       "ticket_id": "<integer>",
    --       "via": {
    --         "channel": "<string>",
    --         "source": {
    --           "commodo_60e": true
    --         }
    --       }
    --     }
    --   ],
    --   "count": "<integer>",
    --   "next_page": "<string>",
    --   "previous_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 @author_id nvarchar(4000)

    DECLARE @created_at nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @Fugiat2_ nvarchar(4000)

    DECLARE @Aliqua4f int

    DECLARE @ticket_id nvarchar(4000)

    DECLARE @Channel nvarchar(4000)

    DECLARE @Amet29d nvarchar(4000)

    DECLARE @Aliqua_b0 nvarchar(4000)

    DECLARE @Amet_24 nvarchar(4000)

    DECLARE @Non_b8 int

    DECLARE @In_3a int

    DECLARE @Occaecat_d98 int

    DECLARE @Commodo_60e int

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @in14 nvarchar(4000)

    DECLARE @consequat_b9 int

    DECLARE @Lorem4 int

    DECLARE @incididunt_a nvarchar(4000)

    DECLARE @ipsume1 int

    DECLARE @laboris_8c nvarchar(4000)

    DECLARE @consectetur6 int

    DECLARE @officia1 int

    DECLARE @minim_27 int

    DECLARE @Ut7_2 nvarchar(4000)

    DECLARE @count nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @count OUT, 'count'
    DECLARE @next_page nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @next_page OUT, 'next_page'
    DECLARE @previous_page nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @previous_page OUT, 'previous_page'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'audits'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @author_id OUT, 'audits[i].author_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'audits[i].created_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'audits[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @Fugiat2_ OUT, 'audits[i].metadata.fugiat2_'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Aliqua4f OUT, 'audits[i].metadata.aliqua4f'
        EXEC sp_OAMethod @jResp, 'StringOf', @ticket_id OUT, 'audits[i].ticket_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @Channel OUT, 'audits[i].via.channel'
        EXEC sp_OAMethod @jResp, 'StringOf', @Amet29d OUT, 'audits[i].via.source.amet29d'
        EXEC sp_OAMethod @jResp, 'StringOf', @Aliqua_b0 OUT, 'audits[i].via.source.aliqua_b0'
        EXEC sp_OAMethod @jResp, 'StringOf', @Amet_24 OUT, 'audits[i].via.source.amet_24'
        EXEC sp_OAMethod @jResp, 'IntOf', @Non_b8 OUT, 'audits[i].via.source.non_b8'
        EXEC sp_OAMethod @jResp, 'IntOf', @In_3a OUT, 'audits[i].metadata.in_3a'
        EXEC sp_OAMethod @jResp, 'IntOf', @Occaecat_d98 OUT, 'audits[i].metadata.occaecat_d98'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Commodo_60e OUT, 'audits[i].via.source.commodo_60e'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'audits[i].events'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @in14 OUT, 'audits[i].events[j].in14'
            EXEC sp_OAMethod @jResp, 'BoolOf', @consequat_b9 OUT, 'audits[i].events[j].consequat_b9'
            EXEC sp_OAMethod @jResp, 'IntOf', @Lorem4 OUT, 'audits[i].events[j].Lorem4'
            EXEC sp_OAMethod @jResp, 'StringOf', @incididunt_a OUT, 'audits[i].events[j].incididunt_a'
            EXEC sp_OAMethod @jResp, 'IntOf', @ipsume1 OUT, 'audits[i].events[j].ipsume1'
            EXEC sp_OAMethod @jResp, 'StringOf', @laboris_8c OUT, 'audits[i].events[j].laboris_8c'
            EXEC sp_OAMethod @jResp, 'BoolOf', @consectetur6 OUT, 'audits[i].events[j].consectetur6'
            EXEC sp_OAMethod @jResp, 'BoolOf', @officia1 OUT, 'audits[i].events[j].officia1'
            EXEC sp_OAMethod @jResp, 'BoolOf', @minim_27 OUT, 'audits[i].events[j].minim_27'
            EXEC sp_OAMethod @jResp, 'StringOf', @Ut7_2 OUT, 'audits[i].events[j].Ut7_2'
            SELECT @j = @j + 1
          END
        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/tickets/:ticket_id/audits

Postman Collection Item JSON

{
  "name": "List Audits for a Ticket",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/tickets/:ticket_id/audits",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "tickets",
        ":ticket_id",
        "audits"
      ],
      "variable": [
        {
          "key": "ticket_id",
          "value": "<integer>"
        }
      ]
    },
    "description": "Lists the audits for a specified ticket.\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**Note**: Audits for [Archived Tickets](https://support.zendesk.com/hc/en-us/articles/4408887617050) do not support pagination for this endpoint.\n\n#### Allowed for\n\n* Agents\n"
  },
  "response": [
    {
      "name": "OK response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/tickets/:ticket_id/audits",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "tickets",
            ":ticket_id",
            "audits"
          ],
          "variable": [
            {
              "key": "ticket_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"audits\": [\n    {\n      \"author_id\": \"<integer>\",\n      \"created_at\": \"<dateTime>\",\n      \"events\": [\n        {\n          \"in14\": 98255426.2140105,\n          \"consequat_b9\": false,\n          \"Lorem4\": -18718960,\n          \"incididunt_a\": 91476803.94307658\n        },\n        {\n          \"ipsume1\": -99329065,\n          \"laboris_8c\": 89859673.3933256,\n          \"consectetur6\": true\n        }\n      ],\n      \"id\": \"<integer>\",\n      \"metadata\": {\n        \"fugiat2_\": 32930402.342455566,\n        \"aliqua4f\": false\n      },\n      \"ticket_id\": \"<integer>\",\n      \"via\": {\n        \"channel\": \"<string>\",\n        \"source\": {\n          \"amet29d\": \"veniam\",\n          \"aliqua_b0\": -53884767.66002053,\n          \"amet_24\": 77146472.24303994,\n          \"non_b8\": 30237848\n        }\n      }\n    },\n    {\n      \"author_id\": \"<integer>\",\n      \"created_at\": \"<dateTime>\",\n      \"events\": [\n        {\n          \"officia1\": true\n        },\n        {\n          \"minim_27\": true,\n          \"Ut7_2\": -37549201.88334068\n        }\n      ],\n      \"id\": \"<integer>\",\n      \"metadata\": {\n        \"in_3a\": 96878618,\n        \"occaecat_d98\": 24309571\n      },\n      \"ticket_id\": \"<integer>\",\n      \"via\": {\n        \"channel\": \"<string>\",\n        \"source\": {\n          \"commodo_60e\": true\n        }\n      }\n    }\n  ],\n  \"count\": \"<integer>\",\n  \"next_page\": \"<string>\",\n  \"previous_page\": \"<string>\"\n}"
    }
  ]
}