Chilkat Online Tools

unicodeC / Support API / Incremental Ticket Event Export

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW queryParams;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *id;
    const wchar_t *instance_id;
    const wchar_t *metric;
    const wchar_t *ticket_id;
    const wchar_t *time;
    const wchar_t *v_type;
    const wchar_t *count;
    const wchar_t *end_of_stream;
    const wchar_t *end_time;
    const wchar_t *next_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 = CkHttpW_Create();

    CkHttpW_putBasicAuth(http,TRUE);
    CkHttpW_putLogin(http,L"login");
    CkHttpW_putPassword(http,L"password");

    queryParams = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(queryParams,L"start_time",L"<integer>");

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://example.zendesk.com/api/v2/incremental/ticket_events",queryParams);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // {
    //   "count": "<integer>",
    //   "end_of_stream": "<boolean>",
    //   "end_time": "<integer>",
    //   "next_page": "<string>",
    //   "ticket_events": [
    //     {
    //       "id": "<integer>",
    //       "instance_id": "<integer>",
    //       "metric": "periodic_update_time",
    //       "ticket_id": "<integer>",
    //       "time": "<dateTime>",
    //       "type": "apply_sla"
    //     },
    //     {
    //       "id": "<integer>",
    //       "instance_id": "<integer>",
    //       "metric": "pausable_update_time",
    //       "ticket_id": "<integer>",
    //       "time": "<dateTime>",
    //       "type": "breach"
    //     }
    //   ]
    // }

    // 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 = CkJsonObjectW_stringOf(jResp,L"count");
    end_of_stream = CkJsonObjectW_stringOf(jResp,L"end_of_stream");
    end_time = CkJsonObjectW_stringOf(jResp,L"end_time");
    next_page = CkJsonObjectW_stringOf(jResp,L"next_page");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"ticket_events");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        id = CkJsonObjectW_stringOf(jResp,L"ticket_events[i].id");
        instance_id = CkJsonObjectW_stringOf(jResp,L"ticket_events[i].instance_id");
        metric = CkJsonObjectW_stringOf(jResp,L"ticket_events[i].metric");
        ticket_id = CkJsonObjectW_stringOf(jResp,L"ticket_events[i].ticket_id");
        time = CkJsonObjectW_stringOf(jResp,L"ticket_events[i].time");
        v_type = CkJsonObjectW_stringOf(jResp,L"ticket_events[i].type");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(queryParams);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl  -u login:password -G -d "start_time=%3Cinteger%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/incremental/ticket_events

Postman Collection Item JSON

{
  "name": "Incremental Ticket Event Export",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/incremental/ticket_events?start_time=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "incremental",
        "ticket_events"
      ],
      "query": [
        {
          "key": "start_time",
          "value": "<integer>",
          "description": "(Required) The time to start the incremental export from"
        }
      ]
    },
    "description": "Returns a stream of changes that occurred on tickets. Each event is tied\nto an update on a ticket and contains all the fields that were updated in that\nchange. For more information, see:\n\n- [Exporting ticket events](/documentation/ticketing/managing-tickets/using-the-incremental-export-api#exporting-ticket-events) in [Using the Incremental Exports API](/documentation/ticketing/managing-tickets/using-the-incremental-export-api)\n- [Time-based incremental exports](/documentation/ticketing/managing-tickets/using-the-incremental-export-api#time-based-incremental-exports) in [Using the Incremental Exports API](/documentation/ticketing/managing-tickets/using-the-incremental-export-api)\n\nYou can include comments in the event stream by using the `comment_events`\nsideload. See Sideloading below. If you don't specify the sideload, any comment\npresent in the ticket update is described only by Boolean `comment_present`\nand `comment_public` object properties in the event's `child_events` array.\nThe comment itself is not included.\n\n#### Allowed For\n\n * Admins\n\n#### Sideloading\n\nThe endpoint supports the `comment_events` sideload. Any comment present in the ticket\nupdate is listed as an object in the event's `child_events` array. Example:\n\n```js\n\"child_events\": [\n  {\n    \"id\": 91048994488,\n    \"via\": {\n      \"channel\": \"api\",\n      \"source\": {\"from\":{},\"to\":{},\"rel\":null}},\n    \"via_reference_id\":null,\n    \"type\": \"Comment\",\n    \"author_id\": 5031726587,\n    \"body\": \"This is a comment\",\n    \"html_body\": \"&lt;div class=\"zd-comment\"&gt;&lt;p dir=\"auto\"&gt;This is a comment&lt;/p&gt;\",\n    \"public\": true,\n    \"attachments\": [],\n    \"audit_id\": 91048994468,\n    \"created_at\": \"2009-06-25T10:15:18Z\",\n    \"event_type\": \"Comment\"\n  },\n  ...\n],\n...\n```\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/incremental/ticket_events?start_time=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "incremental",
            "ticket_events"
          ],
          "query": [
            {
              "key": "start_time",
              "value": "<integer>",
              "description": "(Required) The time to start the incremental export from"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"count\": \"<integer>\",\n  \"end_of_stream\": \"<boolean>\",\n  \"end_time\": \"<integer>\",\n  \"next_page\": \"<string>\",\n  \"ticket_events\": [\n    {\n      \"id\": \"<integer>\",\n      \"instance_id\": \"<integer>\",\n      \"metric\": \"periodic_update_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\": \"breach\"\n    }\n  ]\n}"
    }
  ]
}