Chilkat Online Tools

unicodeCpp / Support API / Update Many Views

Back to Collection Items

#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.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");

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

    CkHttpResponseW *resp = http.QuickRequest(L"PUT",L"https://example.zendesk.com/api/v2/views/update_many");
    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>",
    //   "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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

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

    const wchar_t *count = jResp.stringOf(L"count");
    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"views");
    while (i < count_i) {
        jResp.put_I(i);
        active = jResp.stringOf(L"views[i].active");
        Amet_b2 = jResp.stringOf(L"views[i].conditions.amet_b2");
        Pariatur_d74 = jResp.BoolOf(L"views[i].conditions.pariatur_d74");
        Eiusmodd7e = jResp.IntOf(L"views[i].conditions.eiusmodd7e");
        created_at = jResp.stringOf(L"views[i].created_at");
        default = jResp.stringOf(L"views[i].default");
        description = jResp.stringOf(L"views[i].description");
        Sit_bd1 = jResp.stringOf(L"views[i].execution.sit_bd1");
        Voluptated = jResp.IntOf(L"views[i].execution.voluptated");
        id = jResp.stringOf(L"views[i].id");
        position = jResp.stringOf(L"views[i].position");
        Officia_1c = jResp.stringOf(L"views[i].restriction.officia_1c");
        title = jResp.stringOf(L"views[i].title");
        updated_at = jResp.stringOf(L"views[i].updated_at");
        Do_99 = jResp.IntOf(L"views[i].conditions.do_99");
        Aliqua_ad = jResp.BoolOf(L"views[i].conditions.aliqua_ad");
        Dolore277 = jResp.IntOf(L"views[i].conditions.dolore277");
        Labore0 = jResp.stringOf(L"views[i].conditions.labore0");
        Deserunt00 = jResp.IntOf(L"views[i].execution.deserunt00");
        Velit_90 = jResp.stringOf(L"views[i].execution.velit_90");
        Dolor_58 = jResp.stringOf(L"views[i].restriction.dolor_58");
        Sed_41 = jResp.stringOf(L"views[i].restriction.sed_41");
        i = i + 1;
    }
    }

Curl Command

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

Postman Collection Item JSON

{
  "name": "Update Many Views",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/views/update_many",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "views",
        "update_many"
      ]
    },
    "description": "#### Allowed For\n\n* Agents\n\n#### Request Parameters\n\nThe PUT request expects a `views` object that lists the views to update.\n\nEach view may have the following properties:\n\n| Name     | Mandatory | Description\n| -------- | --------- | -----------\n| id       | yes       | The ID of the view to update\n| position | no        | The new position of the view\n| active   | no        | The active status of the view (true or false)\n\n#### Example Request Body\n\n```js\n{\n  \"views\": [\n    {\"id\": 25, \"position\": 3},\n    {\"id\": 23, \"position\": 5},\n    {\"id\": 27, \"position\": 9},\n    {\"id\": 22, \"position\": 7}\n  ]\n}\n```\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/views/update_many",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "views",
            "update_many"
          ]
        }
      },
      "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}"
    }
  ]
}