Chilkat Online Tools

Objective-C / Support API / Search Views

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

http.BasicAuth = YES;
http.Login = @"login";
http.Password = @"password";

CkoJsonObject *queryParams = [[CkoJsonObject alloc] init];
[queryParams UpdateString: @"query" value: @"<string>"];
[queryParams UpdateString: @"access" value: @"<string>"];
[queryParams UpdateString: @"active" value: @"<boolean>"];
[queryParams UpdateString: @"group_id" value: @"<integer>"];
[queryParams UpdateString: @"sort_by" value: @"<string>"];
[queryParams UpdateString: @"sort_order" value: @"<string>"];
[queryParams UpdateString: @"include" value: @"<string>"];

[http SetRequestHeader: @"Accept" value: @"application/json"];

CkoHttpResponse *resp = [http QuickRequestParams: @"GET" url: @"https://example.zendesk.com/api/v2/views/search" json: queryParams];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",resp.Header);
    NSLog(@"%@",@"Failed.");

    return;
}

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

// {
//   "count": "<integer>",
//   "next_page": "<string>",
//   "previous_page": "<string>",
//   "views": [
//     {
//       "active": "<boolean>",
//       "conditions": {
//         "amet_b2": "minim et Ut aliquip",
//         "pariatur_d74": true,
//         "eiusmodd7e": 16274866
//       },
//       "created_at": "<dateTime>",
//       "default": "<boolean>",
//       "description": "<string>",
//       "execution": {
//         "sit_bd1": -70845421.92699432,
//         "voluptated": -13477997
//       },
//       "id": "<integer>",
//       "position": "<integer>",
//       "restriction": {
//         "officia_1c": -36345253.13616539
//       },
//       "title": "<string>",
//       "updated_at": "<dateTime>"
//     },
//     {
//       "active": "<boolean>",
//       "conditions": {
//         "do_99": 75108528,
//         "aliqua_ad": true,
//         "dolore277": 23927228,
//         "labore0": "incididunt ut dolor"
//       },
//       "created_at": "<dateTime>",
//       "default": "<boolean>",
//       "description": "<string>",
//       "execution": {
//         "deserunt00": 61902530,
//         "velit_90": "consectetur in Excepteur"
//       },
//       "id": "<integer>",
//       "position": "<integer>",
//       "restriction": {
//         "dolor_58": -88642742.97884612,
//         "sed_41": "commodo ut"
//       },
//       "title": "<string>",
//       "updated_at": "<dateTime>"
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

NSString *active = 0;
NSString *Amet_b2 = 0;
BOOL Pariatur_d74;
int Eiusmodd7e;
NSString *created_at = 0;
NSString *default = 0;
NSString *description = 0;
NSString *Sit_bd1 = 0;
int Voluptated;
NSString *id = 0;
NSString *position = 0;
NSString *Officia_1c = 0;
NSString *title = 0;
NSString *updated_at = 0;
int Do_99;
BOOL Aliqua_ad;
int Dolore277;
NSString *Labore0 = 0;
int Deserunt00;
NSString *Velit_90 = 0;
NSString *Dolor_58 = 0;
NSString *Sed_41 = 0;

NSString *count = [jResp StringOf: @"count"];
NSString *next_page = [jResp StringOf: @"next_page"];
NSString *previous_page = [jResp StringOf: @"previous_page"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"views"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    active = [jResp StringOf: @"views[i].active"];
    Amet_b2 = [jResp StringOf: @"views[i].conditions.amet_b2"];
    Pariatur_d74 = [jResp BoolOf: @"views[i].conditions.pariatur_d74"];
    Eiusmodd7e = [[jResp IntOf: @"views[i].conditions.eiusmodd7e"] intValue];
    created_at = [jResp StringOf: @"views[i].created_at"];
    default = [jResp StringOf: @"views[i].default"];
    description = [jResp StringOf: @"views[i].description"];
    Sit_bd1 = [jResp StringOf: @"views[i].execution.sit_bd1"];
    Voluptated = [[jResp IntOf: @"views[i].execution.voluptated"] intValue];
    id = [jResp StringOf: @"views[i].id"];
    position = [jResp StringOf: @"views[i].position"];
    Officia_1c = [jResp StringOf: @"views[i].restriction.officia_1c"];
    title = [jResp StringOf: @"views[i].title"];
    updated_at = [jResp StringOf: @"views[i].updated_at"];
    Do_99 = [[jResp IntOf: @"views[i].conditions.do_99"] intValue];
    Aliqua_ad = [jResp BoolOf: @"views[i].conditions.aliqua_ad"];
    Dolore277 = [[jResp IntOf: @"views[i].conditions.dolore277"] intValue];
    Labore0 = [jResp StringOf: @"views[i].conditions.labore0"];
    Deserunt00 = [[jResp IntOf: @"views[i].execution.deserunt00"] intValue];
    Velit_90 = [jResp StringOf: @"views[i].execution.velit_90"];
    Dolor_58 = [jResp StringOf: @"views[i].restriction.dolor_58"];
    Sed_41 = [jResp StringOf: @"views[i].restriction.sed_41"];
    i = i + 1;
}

Curl Command

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

Postman Collection Item JSON

{
  "name": "Search Views",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/views/search?query=<string>&access=<string>&active=<boolean>&group_id=<integer>&sort_by=<string>&sort_order=<string>&include=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "views",
        "search"
      ],
      "query": [
        {
          "key": "query",
          "value": "<string>",
          "description": "(Required) Query string used to find all views with matching title"
        },
        {
          "key": "access",
          "value": "<string>",
          "description": "Filter views by access. May be \"personal\", \"shared\", or \"account\""
        },
        {
          "key": "active",
          "value": "<boolean>",
          "description": "Filter by active views if true or inactive views if false"
        },
        {
          "key": "group_id",
          "value": "<integer>",
          "description": "Filter views by group"
        },
        {
          "key": "sort_by",
          "value": "<string>",
          "description": "Possible values are \"alphabetical\", \"created_at\", \"updated_at\", and \"position\". If unspecified, the views are sorted by relevance"
        },
        {
          "key": "sort_order",
          "value": "<string>",
          "description": "One of \"asc\" or \"desc\". Defaults to \"asc\" for alphabetical and position sort, \"desc\" for all others"
        },
        {
          "key": "include",
          "value": "<string>",
          "description": "A sideload to include in the response. See [Sideloads](#sideloads-3)"
        }
      ]
    },
    "description": "#### Pagination\n\n* Offset pagination only\n\nSee [Using Offset Pagination](/api-reference/ticketing/introduction/#using-offset-pagination).\n\n#### Allowed For\n\n* Agents\n\n#### Sideloads\n\nThe following sideloads are supported. For more information, see [Side-loading](/documentation/ticketing/using-the-zendesk-api/side_loading/).\n\n| Name             | Will sideload\n| ---------------- | -------------\n| app_installation | The app installation that requires each view, if present\n| permissions      | The permissions for each view\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/views/search?query=<string>&access=<string>&active=<boolean>&group_id=<integer>&sort_by=<string>&sort_order=<string>&include=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "views",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "<string>",
              "description": "(Required) Query string used to find all views with matching title"
            },
            {
              "key": "access",
              "value": "<string>",
              "description": "Filter views by access. May be \"personal\", \"shared\", or \"account\""
            },
            {
              "key": "active",
              "value": "<boolean>",
              "description": "Filter by active views if true or inactive views if false"
            },
            {
              "key": "group_id",
              "value": "<integer>",
              "description": "Filter views by group"
            },
            {
              "key": "sort_by",
              "value": "<string>",
              "description": "Possible values are \"alphabetical\", \"created_at\", \"updated_at\", and \"position\". If unspecified, the views are sorted by relevance"
            },
            {
              "key": "sort_order",
              "value": "<string>",
              "description": "One of \"asc\" or \"desc\". Defaults to \"asc\" for alphabetical and position sort, \"desc\" for all others"
            },
            {
              "key": "include",
              "value": "<string>",
              "description": "A sideload to include in the response. See [Sideloads](#sideloads-3)"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"count\": \"<integer>\",\n  \"next_page\": \"<string>\",\n  \"previous_page\": \"<string>\",\n  \"views\": [\n    {\n      \"active\": \"<boolean>\",\n      \"conditions\": {\n        \"amet_b2\": \"minim et Ut aliquip\",\n        \"pariatur_d74\": true,\n        \"eiusmodd7e\": 16274866\n      },\n      \"created_at\": \"<dateTime>\",\n      \"default\": \"<boolean>\",\n      \"description\": \"<string>\",\n      \"execution\": {\n        \"sit_bd1\": -70845421.92699432,\n        \"voluptated\": -13477997\n      },\n      \"id\": \"<integer>\",\n      \"position\": \"<integer>\",\n      \"restriction\": {\n        \"officia_1c\": -36345253.13616539\n      },\n      \"title\": \"<string>\",\n      \"updated_at\": \"<dateTime>\"\n    },\n    {\n      \"active\": \"<boolean>\",\n      \"conditions\": {\n        \"do_99\": 75108528,\n        \"aliqua_ad\": true,\n        \"dolore277\": 23927228,\n        \"labore0\": \"incididunt ut dolor\"\n      },\n      \"created_at\": \"<dateTime>\",\n      \"default\": \"<boolean>\",\n      \"description\": \"<string>\",\n      \"execution\": {\n        \"deserunt00\": 61902530,\n        \"velit_90\": \"consectetur in Excepteur\"\n      },\n      \"id\": \"<integer>\",\n      \"position\": \"<integer>\",\n      \"restriction\": {\n        \"dolor_58\": -88642742.97884612,\n        \"sed_41\": \"commodo ut\"\n      },\n      \"title\": \"<string>\",\n      \"updated_at\": \"<dateTime>\"\n    }\n  ]\n}"
    }
  ]
}