Chilkat Online Tools

Swift3 / Support API / List Workspaces

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"

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

    let sbResponseBody = CkoStringBuilder()!
    success = http.quickGetSb("https://example.zendesk.com/api/v2/workspaces", sbContent: sbResponseBody)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

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

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

    var respStatusCode: Int = http.lastStatus.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(http.lastHeader!)")
        print("Failed.")
        return
    }

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

    // {
    //   "workspaces": [
    //     {
    //       "activated": "<boolean>",
    //       "apps": [
    //         {
    //           "ut_1": true
    //         },
    //         {
    //           "Lorem_ec": "ut ipsum nulla voluptate",
    //           "sed_a": 38535010.16636646
    //         }
    //       ],
    //       "conditions": {
    //         "all": [
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           },
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           }
    //         ],
    //         "any": [
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           },
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           }
    //         ]
    //       },
    //       "created_at": "<dateTime>",
    //       "description": "<string>",
    //       "id": "<integer>",
    //       "macro_ids": [
    //         "<integer>",
    //         "<integer>"
    //       ],
    //       "macros": [
    //         "<integer>",
    //         "<integer>"
    //       ],
    //       "position": "<integer>",
    //       "prefer_workspace_app_order": "<boolean>",
    //       "selected_macros": [
    //         {
    //           "actions": [
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             },
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             }
    //           ],
    //           "title": "<string>",
    //           "active": "<boolean>",
    //           "created_at": "<dateTime>",
    //           "default": "<boolean>",
    //           "description": "<string>",
    //           "id": "<integer>",
    //           "position": "<integer>",
    //           "restriction": {
    //             "elit_0": 95926683,
    //             "Loreme7": 1915356
    //           },
    //           "updated_at": "<dateTime>",
    //           "url": "<string>",
    //           "app_installation": "<string>",
    //           "categories": "<string>",
    //           "permissions": "<string>",
    //           "usage_1h": "<integer>",
    //           "usage_7d": "<integer>",
    //           "usage_24h": "<integer>",
    //           "usage_30d": "<integer>"
    //         },
    //         {
    //           "actions": [
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             },
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             }
    //           ],
    //           "title": "<string>",
    //           "active": "<boolean>",
    //           "created_at": "<dateTime>",
    //           "default": "<boolean>",
    //           "description": "<string>",
    //           "id": "<integer>",
    //           "position": "<integer>",
    //           "restriction": {
    //             "ut_2": true,
    //             "exf9": false,
    //             "magna_5": false
    //           },
    //           "updated_at": "<dateTime>",
    //           "url": "<string>",
    //           "app_installation": "<string>",
    //           "categories": "<string>",
    //           "permissions": "<string>",
    //           "usage_1h": "<integer>",
    //           "usage_7d": "<integer>",
    //           "usage_24h": "<integer>",
    //           "usage_30d": "<integer>"
    //         }
    //       ],
    //       "ticket_form_id": "<integer>",
    //       "title": "<string>",
    //       "updated_at": "<dateTime>",
    //       "url": "<string>"
    //     },
    //     {
    //       "activated": "<boolean>",
    //       "apps": [
    //         {
    //           "laborum_": "esse elit mollit nulla",
    //           "dolore_72": 44930495
    //         },
    //         {
    //           "Duis_e27": false,
    //           "do_7b": true,
    //           "eu_6": true
    //         }
    //       ],
    //       "conditions": {
    //         "all": [
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           },
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           }
    //         ],
    //         "any": [
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           },
    //           {
    //             "field": "<string>",
    //             "operator": "<string>",
    //             "value": "<string>"
    //           }
    //         ]
    //       },
    //       "created_at": "<dateTime>",
    //       "description": "<string>",
    //       "id": "<integer>",
    //       "macro_ids": [
    //         "<integer>",
    //         "<integer>"
    //       ],
    //       "macros": [
    //         "<integer>",
    //         "<integer>"
    //       ],
    //       "position": "<integer>",
    //       "prefer_workspace_app_order": "<boolean>",
    //       "selected_macros": [
    //         {
    //           "actions": [
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             },
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             }
    //           ],
    //           "title": "<string>",
    //           "active": "<boolean>",
    //           "created_at": "<dateTime>",
    //           "default": "<boolean>",
    //           "description": "<string>",
    //           "id": "<integer>",
    //           "position": "<integer>",
    //           "restriction": {
    //             "nostrud_7": false,
    //             "ex69c": -43731952,
    //             "ut_a": "anim nostrud pariatur",
    //             "mollit__": -87941840
    //           },
    //           "updated_at": "<dateTime>",
    //           "url": "<string>",
    //           "app_installation": "<string>",
    //           "categories": "<string>",
    //           "permissions": "<string>",
    //           "usage_1h": "<integer>",
    //           "usage_7d": "<integer>",
    //           "usage_24h": "<integer>",
    //           "usage_30d": "<integer>"
    //         },
    //         {
    //           "actions": [
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             },
    //             {
    //               "field": "<string>",
    //               "value": "<string>"
    //             }
    //           ],
    //           "title": "<string>",
    //           "active": "<boolean>",
    //           "created_at": "<dateTime>",
    //           "default": "<boolean>",
    //           "description": "<string>",
    //           "id": "<integer>",
    //           "position": "<integer>",
    //           "restriction": {
    //             "deseruntc_": false,
    //             "consequatd0": 17786909,
    //             "id_4a": false
    //           },
    //           "updated_at": "<dateTime>",
    //           "url": "<string>",
    //           "app_installation": "<string>",
    //           "categories": "<string>",
    //           "permissions": "<string>",
    //           "usage_1h": "<integer>",
    //           "usage_7d": "<integer>",
    //           "usage_24h": "<integer>",
    //           "usage_30d": "<integer>"
    //         }
    //       ],
    //       "ticket_form_id": "<integer>",
    //       "title": "<string>",
    //       "updated_at": "<dateTime>",
    //       "url": "<string>"
    //     }
    //   ],
    //   "count": "<integer>",
    //   "next_page": "<string>",
    //   "previous_page": "<string>"
    // }

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

    var activated: String?
    var created_at: String?
    var description: String?
    var id: String?
    var position: String?
    var prefer_workspace_app_order: String?
    var ticket_form_id: String?
    var title: String?
    var updated_at: String?
    var url: String?
    var j: Int
    var count_j: Int
    var ut_1: Bool
    var Lorem_ec: String?
    var sed_a: String?
    var laborum_: String?
    var dolore_72: Int
    var Duis_e27: Bool
    var do_7b: Bool
    var eu_6: Bool
    var field: String?
    var operator: String?
    var value: String?
    var strVal: String?
    var active: String?
    var default: String?
    var Elit_0: Int
    var Loreme7: Int
    var app_installation: String?
    var categories: String?
    var permissions: String?
    var usage_1h: String?
    var usage_7d: String?
    var usage_24h: String?
    var usage_30d: String?
    var Ut_2: Bool
    var Exf9: Bool
    var Magna_5: Bool
    var Nostrud_7: Bool
    var Ex69c: Int
    var Ut_a: String?
    var Mollit__: Int
    var Deseruntc_: Bool
    var Consequatd0: Int
    var Id_4a: Bool
    var k: Int
    var count_k: Int

    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: "workspaces").intValue
    while i < count_i {
        jResp.i = i
        activated = jResp.string(of: "workspaces[i].activated")
        created_at = jResp.string(of: "workspaces[i].created_at")
        description = jResp.string(of: "workspaces[i].description")
        id = jResp.string(of: "workspaces[i].id")
        position = jResp.string(of: "workspaces[i].position")
        prefer_workspace_app_order = jResp.string(of: "workspaces[i].prefer_workspace_app_order")
        ticket_form_id = jResp.string(of: "workspaces[i].ticket_form_id")
        title = jResp.string(of: "workspaces[i].title")
        updated_at = jResp.string(of: "workspaces[i].updated_at")
        url = jResp.string(of: "workspaces[i].url")
        j = 0
        count_j = jResp.size(ofArray: "workspaces[i].apps").intValue
        while j < count_j {
            jResp.j = j
            ut_1 = jResp.bool(of: "workspaces[i].apps[j].ut_1")
            Lorem_ec = jResp.string(of: "workspaces[i].apps[j].Lorem_ec")
            sed_a = jResp.string(of: "workspaces[i].apps[j].sed_a")
            laborum_ = jResp.string(of: "workspaces[i].apps[j].laborum_")
            dolore_72 = jResp.int(of: "workspaces[i].apps[j].dolore_72").intValue
            Duis_e27 = jResp.bool(of: "workspaces[i].apps[j].Duis_e27")
            do_7b = jResp.bool(of: "workspaces[i].apps[j].do_7b")
            eu_6 = jResp.bool(of: "workspaces[i].apps[j].eu_6")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "workspaces[i].conditions.all").intValue
        while j < count_j {
            jResp.j = j
            field = jResp.string(of: "workspaces[i].conditions.all[j].field")
            operator = jResp.string(of: "workspaces[i].conditions.all[j].operator")
            value = jResp.string(of: "workspaces[i].conditions.all[j].value")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "workspaces[i].conditions.any").intValue
        while j < count_j {
            jResp.j = j
            field = jResp.string(of: "workspaces[i].conditions.any[j].field")
            operator = jResp.string(of: "workspaces[i].conditions.any[j].operator")
            value = jResp.string(of: "workspaces[i].conditions.any[j].value")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "workspaces[i].macro_ids").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "workspaces[i].macro_ids[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "workspaces[i].macros").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "workspaces[i].macros[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "workspaces[i].selected_macros").intValue
        while j < count_j {
            jResp.j = j
            title = jResp.string(of: "workspaces[i].selected_macros[j].title")
            active = jResp.string(of: "workspaces[i].selected_macros[j].active")
            created_at = jResp.string(of: "workspaces[i].selected_macros[j].created_at")
            default = jResp.string(of: "workspaces[i].selected_macros[j].default")
            description = jResp.string(of: "workspaces[i].selected_macros[j].description")
            id = jResp.string(of: "workspaces[i].selected_macros[j].id")
            position = jResp.string(of: "workspaces[i].selected_macros[j].position")
            Elit_0 = jResp.int(of: "workspaces[i].selected_macros[j].restriction.elit_0").intValue
            Loreme7 = jResp.int(of: "workspaces[i].selected_macros[j].restriction.Loreme7").intValue
            updated_at = jResp.string(of: "workspaces[i].selected_macros[j].updated_at")
            url = jResp.string(of: "workspaces[i].selected_macros[j].url")
            app_installation = jResp.string(of: "workspaces[i].selected_macros[j].app_installation")
            categories = jResp.string(of: "workspaces[i].selected_macros[j].categories")
            permissions = jResp.string(of: "workspaces[i].selected_macros[j].permissions")
            usage_1h = jResp.string(of: "workspaces[i].selected_macros[j].usage_1h")
            usage_7d = jResp.string(of: "workspaces[i].selected_macros[j].usage_7d")
            usage_24h = jResp.string(of: "workspaces[i].selected_macros[j].usage_24h")
            usage_30d = jResp.string(of: "workspaces[i].selected_macros[j].usage_30d")
            Ut_2 = jResp.bool(of: "workspaces[i].selected_macros[j].restriction.ut_2")
            Exf9 = jResp.bool(of: "workspaces[i].selected_macros[j].restriction.exf9")
            Magna_5 = jResp.bool(of: "workspaces[i].selected_macros[j].restriction.magna_5")
            Nostrud_7 = jResp.bool(of: "workspaces[i].selected_macros[j].restriction.nostrud_7")
            Ex69c = jResp.int(of: "workspaces[i].selected_macros[j].restriction.ex69c").intValue
            Ut_a = jResp.string(of: "workspaces[i].selected_macros[j].restriction.ut_a")
            Mollit__ = jResp.int(of: "workspaces[i].selected_macros[j].restriction.mollit__").intValue
            Deseruntc_ = jResp.bool(of: "workspaces[i].selected_macros[j].restriction.deseruntc_")
            Consequatd0 = jResp.int(of: "workspaces[i].selected_macros[j].restriction.consequatd0").intValue
            Id_4a = jResp.bool(of: "workspaces[i].selected_macros[j].restriction.id_4a")
            k = 0
            count_k = jResp.size(ofArray: "workspaces[i].selected_macros[j].actions").intValue
            while k < count_k {
                jResp.k = k
                field = jResp.string(of: "workspaces[i].selected_macros[j].actions[k].field")
                value = jResp.string(of: "workspaces[i].selected_macros[j].actions[k].value")
                k = k + 1
            }

            j = j + 1
        }

        i = i + 1
    }


}

Curl Command

curl  -u login:password -X GET
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/workspaces

Postman Collection Item JSON

{
  "name": "List Workspaces",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/workspaces",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "workspaces"
      ]
    },
    "description": "#### Allowed For\n\n* Admins, 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/workspaces",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "workspaces"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"workspaces\": [\n    {\n      \"activated\": \"<boolean>\",\n      \"apps\": [\n        {\n          \"ut_1\": true\n        },\n        {\n          \"Lorem_ec\": \"ut ipsum nulla voluptate\",\n          \"sed_a\": 38535010.16636646\n        }\n      ],\n      \"conditions\": {\n        \"all\": [\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          },\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          }\n        ],\n        \"any\": [\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          },\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          }\n        ]\n      },\n      \"created_at\": \"<dateTime>\",\n      \"description\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"macro_ids\": [\n        \"<integer>\",\n        \"<integer>\"\n      ],\n      \"macros\": [\n        \"<integer>\",\n        \"<integer>\"\n      ],\n      \"position\": \"<integer>\",\n      \"prefer_workspace_app_order\": \"<boolean>\",\n      \"selected_macros\": [\n        {\n          \"actions\": [\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            },\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            }\n          ],\n          \"title\": \"<string>\",\n          \"active\": \"<boolean>\",\n          \"created_at\": \"<dateTime>\",\n          \"default\": \"<boolean>\",\n          \"description\": \"<string>\",\n          \"id\": \"<integer>\",\n          \"position\": \"<integer>\",\n          \"restriction\": {\n            \"elit_0\": 95926683,\n            \"Loreme7\": 1915356\n          },\n          \"updated_at\": \"<dateTime>\",\n          \"url\": \"<string>\",\n          \"app_installation\": \"<string>\",\n          \"categories\": \"<string>\",\n          \"permissions\": \"<string>\",\n          \"usage_1h\": \"<integer>\",\n          \"usage_7d\": \"<integer>\",\n          \"usage_24h\": \"<integer>\",\n          \"usage_30d\": \"<integer>\"\n        },\n        {\n          \"actions\": [\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            },\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            }\n          ],\n          \"title\": \"<string>\",\n          \"active\": \"<boolean>\",\n          \"created_at\": \"<dateTime>\",\n          \"default\": \"<boolean>\",\n          \"description\": \"<string>\",\n          \"id\": \"<integer>\",\n          \"position\": \"<integer>\",\n          \"restriction\": {\n            \"ut_2\": true,\n            \"exf9\": false,\n            \"magna_5\": false\n          },\n          \"updated_at\": \"<dateTime>\",\n          \"url\": \"<string>\",\n          \"app_installation\": \"<string>\",\n          \"categories\": \"<string>\",\n          \"permissions\": \"<string>\",\n          \"usage_1h\": \"<integer>\",\n          \"usage_7d\": \"<integer>\",\n          \"usage_24h\": \"<integer>\",\n          \"usage_30d\": \"<integer>\"\n        }\n      ],\n      \"ticket_form_id\": \"<integer>\",\n      \"title\": \"<string>\",\n      \"updated_at\": \"<dateTime>\",\n      \"url\": \"<string>\"\n    },\n    {\n      \"activated\": \"<boolean>\",\n      \"apps\": [\n        {\n          \"laborum_\": \"esse elit mollit nulla\",\n          \"dolore_72\": 44930495\n        },\n        {\n          \"Duis_e27\": false,\n          \"do_7b\": true,\n          \"eu_6\": true\n        }\n      ],\n      \"conditions\": {\n        \"all\": [\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          },\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          }\n        ],\n        \"any\": [\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          },\n          {\n            \"field\": \"<string>\",\n            \"operator\": \"<string>\",\n            \"value\": \"<string>\"\n          }\n        ]\n      },\n      \"created_at\": \"<dateTime>\",\n      \"description\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"macro_ids\": [\n        \"<integer>\",\n        \"<integer>\"\n      ],\n      \"macros\": [\n        \"<integer>\",\n        \"<integer>\"\n      ],\n      \"position\": \"<integer>\",\n      \"prefer_workspace_app_order\": \"<boolean>\",\n      \"selected_macros\": [\n        {\n          \"actions\": [\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            },\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            }\n          ],\n          \"title\": \"<string>\",\n          \"active\": \"<boolean>\",\n          \"created_at\": \"<dateTime>\",\n          \"default\": \"<boolean>\",\n          \"description\": \"<string>\",\n          \"id\": \"<integer>\",\n          \"position\": \"<integer>\",\n          \"restriction\": {\n            \"nostrud_7\": false,\n            \"ex69c\": -43731952,\n            \"ut_a\": \"anim nostrud pariatur\",\n            \"mollit__\": -87941840\n          },\n          \"updated_at\": \"<dateTime>\",\n          \"url\": \"<string>\",\n          \"app_installation\": \"<string>\",\n          \"categories\": \"<string>\",\n          \"permissions\": \"<string>\",\n          \"usage_1h\": \"<integer>\",\n          \"usage_7d\": \"<integer>\",\n          \"usage_24h\": \"<integer>\",\n          \"usage_30d\": \"<integer>\"\n        },\n        {\n          \"actions\": [\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            },\n            {\n              \"field\": \"<string>\",\n              \"value\": \"<string>\"\n            }\n          ],\n          \"title\": \"<string>\",\n          \"active\": \"<boolean>\",\n          \"created_at\": \"<dateTime>\",\n          \"default\": \"<boolean>\",\n          \"description\": \"<string>\",\n          \"id\": \"<integer>\",\n          \"position\": \"<integer>\",\n          \"restriction\": {\n            \"deseruntc_\": false,\n            \"consequatd0\": 17786909,\n            \"id_4a\": false\n          },\n          \"updated_at\": \"<dateTime>\",\n          \"url\": \"<string>\",\n          \"app_installation\": \"<string>\",\n          \"categories\": \"<string>\",\n          \"permissions\": \"<string>\",\n          \"usage_1h\": \"<integer>\",\n          \"usage_7d\": \"<integer>\",\n          \"usage_24h\": \"<integer>\",\n          \"usage_30d\": \"<integer>\"\n        }\n      ],\n      \"ticket_form_id\": \"<integer>\",\n      \"title\": \"<string>\",\n      \"updated_at\": \"<dateTime>\",\n      \"url\": \"<string>\"\n    }\n  ],\n  \"count\": \"<integer>\",\n  \"next_page\": \"<string>\",\n  \"previous_page\": \"<string>\"\n}"
    }
  ]
}