Chilkat Online Tools

PureBasic / Support API / List Audits for a Ticket

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.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")

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

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

    success = CkHttp::ckQuickGetSb(http,"https://example.zendesk.com/api/v2/tickets/:ticket_id/audits",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    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 = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; 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

    author_id.s
    created_at.s
    id.s
    Fugiat2_.s
    Aliqua4f.i
    ticket_id.s
    Channel.s
    Amet29d.s
    Aliqua_b0.s
    Amet_24.s
    Non_b8.i
    In_3a.i
    Occaecat_d98.i
    Commodo_60e.i
    j.i
    count_j.i
    in14.s
    consequat_b9.i
    Lorem4.i
    incididunt_a.s
    ipsume1.i
    laboris_8c.s
    consectetur6.i
    officia1.i
    minim_27.i
    Ut7_2.s

    count.s = CkJsonObject::ckStringOf(jResp,"count")
    next_page.s = CkJsonObject::ckStringOf(jResp,"next_page")
    previous_page.s = CkJsonObject::ckStringOf(jResp,"previous_page")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"audits")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        author_id = CkJsonObject::ckStringOf(jResp,"audits[i].author_id")
        created_at = CkJsonObject::ckStringOf(jResp,"audits[i].created_at")
        id = CkJsonObject::ckStringOf(jResp,"audits[i].id")
        Fugiat2_ = CkJsonObject::ckStringOf(jResp,"audits[i].metadata.fugiat2_")
        Aliqua4f = CkJsonObject::ckBoolOf(jResp,"audits[i].metadata.aliqua4f")
        ticket_id = CkJsonObject::ckStringOf(jResp,"audits[i].ticket_id")
        Channel = CkJsonObject::ckStringOf(jResp,"audits[i].via.channel")
        Amet29d = CkJsonObject::ckStringOf(jResp,"audits[i].via.source.amet29d")
        Aliqua_b0 = CkJsonObject::ckStringOf(jResp,"audits[i].via.source.aliqua_b0")
        Amet_24 = CkJsonObject::ckStringOf(jResp,"audits[i].via.source.amet_24")
        Non_b8 = CkJsonObject::ckIntOf(jResp,"audits[i].via.source.non_b8")
        In_3a = CkJsonObject::ckIntOf(jResp,"audits[i].metadata.in_3a")
        Occaecat_d98 = CkJsonObject::ckIntOf(jResp,"audits[i].metadata.occaecat_d98")
        Commodo_60e = CkJsonObject::ckBoolOf(jResp,"audits[i].via.source.commodo_60e")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"audits[i].events")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            in14 = CkJsonObject::ckStringOf(jResp,"audits[i].events[j].in14")
            consequat_b9 = CkJsonObject::ckBoolOf(jResp,"audits[i].events[j].consequat_b9")
            Lorem4 = CkJsonObject::ckIntOf(jResp,"audits[i].events[j].Lorem4")
            incididunt_a = CkJsonObject::ckStringOf(jResp,"audits[i].events[j].incididunt_a")
            ipsume1 = CkJsonObject::ckIntOf(jResp,"audits[i].events[j].ipsume1")
            laboris_8c = CkJsonObject::ckStringOf(jResp,"audits[i].events[j].laboris_8c")
            consectetur6 = CkJsonObject::ckBoolOf(jResp,"audits[i].events[j].consectetur6")
            officia1 = CkJsonObject::ckBoolOf(jResp,"audits[i].events[j].officia1")
            minim_27 = CkJsonObject::ckBoolOf(jResp,"audits[i].events[j].minim_27")
            Ut7_2 = CkJsonObject::ckStringOf(jResp,"audits[i].events[j].Ut7_2")
            j = j + 1
        Wend
        i = i + 1
    Wend


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


    ProcedureReturn
EndProcedure

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