Chilkat Online Tools

Swift3 / Support API / List Active Views

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

    http.basicAuth = true
    http.login = "login"
    http.password = "password"

    let queryParams = CkoJsonObject()!
    queryParams.update("access", value: "<string>")
    queryParams.update("group_id", value: "<integer>")
    queryParams.update("sort_by", value: "<string>")
    queryParams.update("sort_order", value: "<string>")

    http.setRequestHeader("Accept", value: "application/json")

    var resp: CkoHttpResponse? = http.quickRequestParams("GET", url: "https://example.zendesk.com/api/v2/views/active", json: queryParams)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp!.getBodySb(sbResponseBody)

    let jResp = CkoJsonObject()!
    jResp.loadSb(sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = resp!.statusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp!.header!)")
        print("Failed.")
        resp = nil
        return
    }

    resp = nil

    // 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

    var active: String?
    var Amet_b2: String?
    var Pariatur_d74: Bool
    var Eiusmodd7e: Int
    var created_at: String?
    var default: String?
    var description: String?
    var Sit_bd1: String?
    var Voluptated: Int
    var id: String?
    var position: String?
    var Officia_1c: String?
    var title: String?
    var updated_at: String?
    var Do_99: Int
    var Aliqua_ad: Bool
    var Dolore277: Int
    var Labore0: String?
    var Deserunt00: Int
    var Velit_90: String?
    var Dolor_58: String?
    var Sed_41: String?

    var count: String? = jResp.string(of: "count")
    var next_page: String? = jResp.string(of: "next_page")
    var previous_page: String? = jResp.string(of: "previous_page")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "views").intValue
    while i < count_i {
        jResp.i = i
        active = jResp.string(of: "views[i].active")
        Amet_b2 = jResp.string(of: "views[i].conditions.amet_b2")
        Pariatur_d74 = jResp.bool(of: "views[i].conditions.pariatur_d74")
        Eiusmodd7e = jResp.int(of: "views[i].conditions.eiusmodd7e").intValue
        created_at = jResp.string(of: "views[i].created_at")
        default = jResp.string(of: "views[i].default")
        description = jResp.string(of: "views[i].description")
        Sit_bd1 = jResp.string(of: "views[i].execution.sit_bd1")
        Voluptated = jResp.int(of: "views[i].execution.voluptated").intValue
        id = jResp.string(of: "views[i].id")
        position = jResp.string(of: "views[i].position")
        Officia_1c = jResp.string(of: "views[i].restriction.officia_1c")
        title = jResp.string(of: "views[i].title")
        updated_at = jResp.string(of: "views[i].updated_at")
        Do_99 = jResp.int(of: "views[i].conditions.do_99").intValue
        Aliqua_ad = jResp.bool(of: "views[i].conditions.aliqua_ad")
        Dolore277 = jResp.int(of: "views[i].conditions.dolore277").intValue
        Labore0 = jResp.string(of: "views[i].conditions.labore0")
        Deserunt00 = jResp.int(of: "views[i].execution.deserunt00").intValue
        Velit_90 = jResp.string(of: "views[i].execution.velit_90")
        Dolor_58 = jResp.string(of: "views[i].restriction.dolor_58")
        Sed_41 = jResp.string(of: "views[i].restriction.sed_41")
        i = i + 1
    }


}

Curl Command

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

Postman Collection Item JSON

{
  "name": "List Active Views",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/views/active?access=<string>&group_id=<integer>&sort_by=<string>&sort_order=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "views",
        "active"
      ],
      "query": [
        {
          "key": "access",
          "value": "<string>",
          "description": "Only views with given access. May be \"personal\", \"shared\", or \"account\""
        },
        {
          "key": "group_id",
          "value": "<integer>",
          "description": "Only views belonging to given group"
        },
        {
          "key": "sort_by",
          "value": "<string>",
          "description": "Possible values are \"alphabetical\", \"created_at\", or \"updated_at\". Defaults to \"position\""
        },
        {
          "key": "sort_order",
          "value": "<string>",
          "description": "One of \"asc\" or \"desc\". Defaults to \"asc\" for alphabetical and position sort, \"desc\" for all others"
        }
      ]
    },
    "description": "Lists active shared and personal views available to the current user.\n\n#### Sideloads\n\nThe following sideloads are supported:\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\n#### Pagination\n\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"
  },
  "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/active?access=<string>&group_id=<integer>&sort_by=<string>&sort_order=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "views",
            "active"
          ],
          "query": [
            {
              "key": "access",
              "value": "<string>",
              "description": "Only views with given access. May be \"personal\", \"shared\", or \"account\""
            },
            {
              "key": "group_id",
              "value": "<integer>",
              "description": "Only views belonging to given group"
            },
            {
              "key": "sort_by",
              "value": "<string>",
              "description": "Possible values are \"alphabetical\", \"created_at\", or \"updated_at\". Defaults to \"position\""
            },
            {
              "key": "sort_order",
              "value": "<string>",
              "description": "One of \"asc\" or \"desc\". Defaults to \"asc\" for alphabetical and position sort, \"desc\" for all others"
            }
          ]
        }
      },
      "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}"
    }
  ]
}