Chilkat Online Tools

C / Support API / Export Search Results

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 *created_at;
    const char *default;
    const char *deleted;
    const char *description;
    const char *id;
    const char *name;
    const char *result_type;
    const char *updated_at;
    const char *url;
    const char *facets;
    const char *v_Next;
    const char *Prev;
    const char *After_cursor;
    const char *Before_cursor;
    const char *Has_more;
    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,"query","<string>");
    CkJsonObject_UpdateString(queryParams,"page[size]","<integer>");
    CkJsonObject_UpdateString(queryParams,"filter[type]","<string>");

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

    resp = CkHttp_QuickRequestParams(http,"GET","https://example.zendesk.com/api/v2/search/export",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)

    // {
    //   "facets": "<string>",
    //   "links": {
    //     "next": "<string>",
    //     "prev": "<string>"
    //   },
    //   "meta": {
    //     "after_cursor": "<string>",
    //     "before_cursor": "<string>",
    //     "has_more": "<boolean>"
    //   },
    //   "results": [
    //     {
    //       "created_at": "<string>",
    //       "default": "<boolean>",
    //       "deleted": "<boolean>",
    //       "description": "<string>",
    //       "id": "<integer>",
    //       "name": "<string>",
    //       "result_type": "<string>",
    //       "updated_at": "<string>",
    //       "url": "<string>"
    //     },
    //     {
    //       "created_at": "<string>",
    //       "default": "<boolean>",
    //       "deleted": "<boolean>",
    //       "description": "<string>",
    //       "id": "<integer>",
    //       "name": "<string>",
    //       "result_type": "<string>",
    //       "updated_at": "<string>",
    //       "url": "<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.

    facets = CkJsonObject_stringOf(jResp,"facets");
    v_Next = CkJsonObject_stringOf(jResp,"links.next");
    Prev = CkJsonObject_stringOf(jResp,"links.prev");
    After_cursor = CkJsonObject_stringOf(jResp,"meta.after_cursor");
    Before_cursor = CkJsonObject_stringOf(jResp,"meta.before_cursor");
    Has_more = CkJsonObject_stringOf(jResp,"meta.has_more");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"results");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        created_at = CkJsonObject_stringOf(jResp,"results[i].created_at");
        default = CkJsonObject_stringOf(jResp,"results[i].default");
        deleted = CkJsonObject_stringOf(jResp,"results[i].deleted");
        description = CkJsonObject_stringOf(jResp,"results[i].description");
        id = CkJsonObject_stringOf(jResp,"results[i].id");
        name = CkJsonObject_stringOf(jResp,"results[i].name");
        result_type = CkJsonObject_stringOf(jResp,"results[i].result_type");
        updated_at = CkJsonObject_stringOf(jResp,"results[i].updated_at");
        url = CkJsonObject_stringOf(jResp,"results[i].url");
        i = i + 1;
    }



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

    }

Curl Command

curl  -u login:password -G -d "query=%3Cstring%3E"
	-d "page[size]=%3Cinteger%3E"
	-d "filter[type]=%3Cstring%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/search/export

Postman Collection Item JSON

{
  "name": "Export Search Results",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/search/export?query=<string>&page[size]=<integer>&filter[type]=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "search",
        "export"
      ],
      "query": [
        {
          "key": "query",
          "value": "<string>",
          "description": "(Required) The search query. See [Query basics](#query-basics) above. For details on the query syntax, see the [Zendesk Support search reference](https://support.zendesk.com/hc/en-us/articles/203663226)"
        },
        {
          "key": "page[size]",
          "value": "<integer>",
          "description": "The number of results shown in a page."
        },
        {
          "key": "filter[type]",
          "value": "<string>",
          "description": "The object type returned by the export query. Can be `ticket`, `organization`, `user`, or `group`."
        }
      ]
    },
    "description": "Exports a set of results. See [Query basics](#query-basics) for the syntax of the `query` parameter.\n\nThis endpoint is for search queries that will return more than 1000 results. The result set is ordered only by the `created_at` attribute.\n\nThe search only returns results of a single object type. The following object types are supported: ticket, organization, user, or group.\n\nYou must specify the type in the `filter[type]` parameter. Searches with type in the query string will result in an error.\n\n#### Allowed For\n\n- Agents\n\n#### Pagination\n\n- Cursor pagination\n\nSee [Pagination](/api-reference/introduction/pagination/).\n\nReturns a maximum of 1000 records per page. The number of results shown in a page is determined by the `page[size]` parameter.\n\n**Note**: You may experience a speed reduction or a timeout if you request 1000 results per page and you have many archived tickets in the results. Try reducing the number of results per page. We recommend 100 results per page.\n\nThe cursor specified by the `after_cursor` property in a response expires after one hour.\n\nFor more information on cursor-based pagination, see the following articles:\n\n- [Comparing cursor pagination and offset pagination](/documentation/developer-tools/pagination/comparing-cursor-pagination-and-offset-pagination)\n- [Paginating through lists using cursor pagination](/documentation/developer-tools/pagination/paginating-through-lists-using-cursor-pagination)\n\n#### Limits\n\nThis API endpoint is rate-limited to 100 requests per minute per account. The limit also counts towards the global API rate limit.\n\n#### Response Format\n\n| Name                  | Type                 | Comment\n| --------------------- | ---------------------| --------------------\n| links[next]           | string               | URL to the next page of results\n| meta[has_more]        | string               | Boolean indicating if there are more results\n| meta[after_cursor]    | string               | Cursor object returned from the Search Service\n| results               | array                | May consist of tickets, users, groups, or organizations, as specified by the `filter_type` parameter\n\nThe response is similar to the response of `GET /api/v2/search.json?`, with a few changes:\n\n* `links` - Has the following nested properties: `prev` and `next`. These replace the `next_page` and `prev_page` links. The `prev` property is always null because backward pagination is not supported. The `next` property may include an auto-generated link to the next page of results.\n* `meta` - Has the following nested properties: `has_more` and `after_cursor`. The `has_more` property indicates whether the next page has more results. The `after_cursor` property is the cursor used to paginate to the next page. It expires after one hour.\n\nThere's no `count` property.\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/search/export?query=<string>&page[size]=<integer>&filter[type]=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "search",
            "export"
          ],
          "query": [
            {
              "key": "query",
              "value": "<string>",
              "description": "(Required) The search query. See [Query basics](#query-basics) above. For details on the query syntax, see the [Zendesk Support search reference](https://support.zendesk.com/hc/en-us/articles/203663226)"
            },
            {
              "key": "page[size]",
              "value": "<integer>",
              "description": "The number of results shown in a page."
            },
            {
              "key": "filter[type]",
              "value": "<string>",
              "description": "The object type returned by the export query. Can be `ticket`, `organization`, `user`, or `group`."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"facets\": \"<string>\",\n  \"links\": {\n    \"next\": \"<string>\",\n    \"prev\": \"<string>\"\n  },\n  \"meta\": {\n    \"after_cursor\": \"<string>\",\n    \"before_cursor\": \"<string>\",\n    \"has_more\": \"<boolean>\"\n  },\n  \"results\": [\n    {\n      \"created_at\": \"<string>\",\n      \"default\": \"<boolean>\",\n      \"deleted\": \"<boolean>\",\n      \"description\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"name\": \"<string>\",\n      \"result_type\": \"<string>\",\n      \"updated_at\": \"<string>\",\n      \"url\": \"<string>\"\n    },\n    {\n      \"created_at\": \"<string>\",\n      \"default\": \"<boolean>\",\n      \"deleted\": \"<boolean>\",\n      \"description\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"name\": \"<string>\",\n      \"result_type\": \"<string>\",\n      \"updated_at\": \"<string>\",\n      \"url\": \"<string>\"\n    }\n  ]\n}"
    }
  ]
}