Chilkat Online Tools

unicodeCpp / Support API / List Search Results

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;
    bool success;

    http.put_BasicAuth(true);
    http.put_Login(L"login");
    http.put_Password(L"password");

    CkJsonObjectW queryParams;
    queryParams.UpdateString(L"query",L"<string>");
    queryParams.UpdateString(L"sort_by",L"<string>");
    queryParams.UpdateString(L"sort_order",L"<string>");

    http.SetRequestHeader(L"Accept",L"application/json");

    CkHttpResponseW *resp = http.QuickRequestParams(L"GET",L"https://example.zendesk.com/api/v2/search",queryParams);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

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

    int respStatusCode = resp->get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp->header());
        wprintf(L"Failed.\n");
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "count": "<integer>",
    //   "facets": "<string>",
    //   "next_page": "<string>",
    //   "previous_page": "<string>",
    //   "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.

    const wchar_t *created_at = 0;
    const wchar_t *default = 0;
    const wchar_t *deleted = 0;
    const wchar_t *description = 0;
    const wchar_t *id = 0;
    const wchar_t *name = 0;
    const wchar_t *result_type = 0;
    const wchar_t *updated_at = 0;
    const wchar_t *url = 0;

    const wchar_t *count = jResp.stringOf(L"count");
    const wchar_t *facets = jResp.stringOf(L"facets");
    const wchar_t *next_page = jResp.stringOf(L"next_page");
    const wchar_t *previous_page = jResp.stringOf(L"previous_page");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"results");
    while (i < count_i) {
        jResp.put_I(i);
        created_at = jResp.stringOf(L"results[i].created_at");
        default = jResp.stringOf(L"results[i].default");
        deleted = jResp.stringOf(L"results[i].deleted");
        description = jResp.stringOf(L"results[i].description");
        id = jResp.stringOf(L"results[i].id");
        name = jResp.stringOf(L"results[i].name");
        result_type = jResp.stringOf(L"results[i].result_type");
        updated_at = jResp.stringOf(L"results[i].updated_at");
        url = jResp.stringOf(L"results[i].url");
        i = i + 1;
    }
    }

Curl Command

curl  -u login:password -G -d "query=%3Cstring%3E"
	-d "sort_by=%3Cstring%3E"
	-d "sort_order=%3Cstring%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/search

Postman Collection Item JSON

{
  "name": "List Search Results",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/search?query=<string>&sort_by=<string>&sort_order=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "search"
      ],
      "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": "sort_by",
          "value": "<string>",
          "description": "One of `updated_at`, `created_at`, `priority`, `status`, or `ticket_type`. Defaults to sorting by relevance"
        },
        {
          "key": "sort_order",
          "value": "<string>",
          "description": "One of `asc` or `desc`.  Defaults to `desc`"
        }
      ]
    },
    "description": "Use the ampersand character (&) to append the `sort_by` or `sort_order` parameters to the URL.\n\nFor examples, see [Searching with Zendesk API](/documentation/ticketing/using-the-zendesk-api/searching-with-the-zendesk-api).\n\n#### Pagination\n\n* Offset pagination only\n\nOffset pagination may result in duplicate results when paging. You can also use the \n[Export Search Results](/api-reference/ticketing/ticket-management/search/#export-search-results) endpoint, which \nuses cursor-based pagination and doesn't return duplicate results. See \n[Pagination](/api-reference/introduction/pagination/) for more information.\n\n#### Allowed For\n\n* Admins, Agents and Light Agents\n\n\n#### Errors JSON Format\n\nErrors are represented as JSON objects which have the following keys:\n\n| Name                  | Type                 | Comment\n| --------------------- | ---------------------| --------------------\n| error                 | string               | The type of error. Examples: \"unavailable\", \"invalid\"\n| description           | string               |\n\n##### Example Error\n```js\n{\n  \"error\": \"unavailable\",\n  \"description\": \"Sorry, we could not complete your search query. Please try again in a moment.\"\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/search?query=<string>&sort_by=<string>&sort_order=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "search"
          ],
          "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": "sort_by",
              "value": "<string>",
              "description": "One of `updated_at`, `created_at`, `priority`, `status`, or `ticket_type`. Defaults to sorting by relevance"
            },
            {
              "key": "sort_order",
              "value": "<string>",
              "description": "One of `asc` or `desc`.  Defaults to `desc`"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"count\": \"<integer>\",\n  \"facets\": \"<string>\",\n  \"next_page\": \"<string>\",\n  \"previous_page\": \"<string>\",\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}"
    }
  ]
}