Chilkat Online Tools

C / Support API / List deleted tickets

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject queryParams;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *Id;
    const char *Name;
    const char *deleted_at;
    const char *id;
    const char *previous_state;
    const char *subject;
    const char *count;
    const char *next_page;
    const char *previous_page;
    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");

    queryParams = CkJsonObject_Create();
    CkJsonObject_UpdateString(queryParams,"sort_by","id");
    CkJsonObject_UpdateString(queryParams,"sort_order","asc");

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

    resp = CkHttp_QuickRequestParams(http,"GET","https://example.zendesk.com/api/v2/deleted_tickets",queryParams);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);

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

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

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

    CkHttpResponse_Dispose(resp);

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

    // {
    //   "deleted_tickets": [
    //     {
    //       "actor": {
    //         "id": "<integer>",
    //         "name": "<string>"
    //       },
    //       "deleted_at": "<string>",
    //       "id": "<integer>",
    //       "previous_state": "<string>",
    //       "subject": "<string>"
    //     },
    //     {
    //       "actor": {
    //         "id": "<integer>",
    //         "name": "<string>"
    //       },
    //       "deleted_at": "<string>",
    //       "id": "<integer>",
    //       "previous_state": "<string>",
    //       "subject": "<string>"
    //     }
    //   ],
    //   "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

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

    count = CkJsonObject_stringOf(jResp,"count");
    next_page = CkJsonObject_stringOf(jResp,"next_page");
    previous_page = CkJsonObject_stringOf(jResp,"previous_page");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"deleted_tickets");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        Id = CkJsonObject_stringOf(jResp,"deleted_tickets[i].actor.id");
        Name = CkJsonObject_stringOf(jResp,"deleted_tickets[i].actor.name");
        deleted_at = CkJsonObject_stringOf(jResp,"deleted_tickets[i].deleted_at");
        id = CkJsonObject_stringOf(jResp,"deleted_tickets[i].id");
        previous_state = CkJsonObject_stringOf(jResp,"deleted_tickets[i].previous_state");
        subject = CkJsonObject_stringOf(jResp,"deleted_tickets[i].subject");
        i = i + 1;
    }



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

    }

Curl Command

curl  -u login:password -G -d "sort_by=id"
	-d "sort_order=asc"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/deleted_tickets

Postman Collection Item JSON

{
  "name": "List deleted tickets",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/deleted_tickets?sort_by=id&sort_order=asc",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "deleted_tickets"
      ],
      "query": [
        {
          "key": "sort_by",
          "value": "id",
          "description": "Sort by"
        },
        {
          "key": "sort_order",
          "value": "asc",
          "description": "Sort order. Defaults to \"asc\""
        }
      ]
    },
    "description": "Returns a maximum of 100 deleted tickets per page. See [Pagination](/api-reference/introduction/pagination/).\n\nThe results includes all deleted (and not yet archived) tickets that\nhave not yet been [scrubbed](https://support.zendesk.com/hc/en-us/articles/4408845703194#topic_fv5_w51_sdb) in the past 30 days. Archived tickets are\nnot included in the results. See [About archived tickets](https://support.zendesk.com/hc/en-us/articles/203657756)\nin the Support Help Center.\n\nThe tickets are ordered chronologically by created date, from oldest to newest.\nThe first ticket listed may not be the oldest ticket in your\naccount due to [ticket archiving](https://support.zendesk.com/hc/en-us/articles/203657756).\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#### Allowed For\n\n* Agents\n\n#### Rate Limit\n\nYou can make 10 requests every 1 minute using this endpoint.\nWhen making requests beyond page 100, you can make 5 requests every 1 minute.\nThe rate limiting mechanism behaves as described in\n[Monitoring your request activity](/api-reference/ticketing/account-configuration/usage_limits/#monitoring-your-request-activity) in the API introduction."
  },
  "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/deleted_tickets?sort_by=id&sort_order=asc",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "deleted_tickets"
          ],
          "query": [
            {
              "key": "sort_by",
              "value": "id",
              "description": "Sort by"
            },
            {
              "key": "sort_order",
              "value": "asc",
              "description": "Sort order. Defaults to \"asc\""
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"deleted_tickets\": [\n    {\n      \"actor\": {\n        \"id\": \"<integer>\",\n        \"name\": \"<string>\"\n      },\n      \"deleted_at\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"previous_state\": \"<string>\",\n      \"subject\": \"<string>\"\n    },\n    {\n      \"actor\": {\n        \"id\": \"<integer>\",\n        \"name\": \"<string>\"\n      },\n      \"deleted_at\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"previous_state\": \"<string>\",\n      \"subject\": \"<string>\"\n    }\n  ],\n  \"count\": \"<integer>\",\n  \"next_page\": \"<string>\",\n  \"previous_page\": \"<string>\"\n}"
    }
  ]
}