Chilkat Online Tools

unicodeCpp / Support API / Create Workspace

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");

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "workspace": {
    //     "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>"
    //         }
    //       ]
    //     },
    //     "description": "<string>",
    //     "macros": [
    //       "<number>",
    //       "<number>"
    //     ],
    //     "ticket_form_id": "<number>",
    //     "title": "<string>"
    //   }
    // }

    CkJsonObjectW json;
    json.UpdateString(L"workspace.conditions.all[0].field",L"<string>");
    json.UpdateString(L"workspace.conditions.all[0].operator",L"<string>");
    json.UpdateString(L"workspace.conditions.all[0].value",L"<string>");
    json.UpdateString(L"workspace.conditions.all[1].field",L"<string>");
    json.UpdateString(L"workspace.conditions.all[1].operator",L"<string>");
    json.UpdateString(L"workspace.conditions.all[1].value",L"<string>");
    json.UpdateString(L"workspace.conditions.any[0].field",L"<string>");
    json.UpdateString(L"workspace.conditions.any[0].operator",L"<string>");
    json.UpdateString(L"workspace.conditions.any[0].value",L"<string>");
    json.UpdateString(L"workspace.conditions.any[1].field",L"<string>");
    json.UpdateString(L"workspace.conditions.any[1].operator",L"<string>");
    json.UpdateString(L"workspace.conditions.any[1].value",L"<string>");
    json.UpdateString(L"workspace.description",L"<string>");
    json.UpdateString(L"workspace.macros[0]",L"<number>");
    json.UpdateString(L"workspace.macros[1]",L"<number>");
    json.UpdateString(L"workspace.ticket_form_id",L"<number>");
    json.UpdateString(L"workspace.title",L"<string>");

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

    CkHttpResponseW *resp = http.PostJson3(L"https://example.zendesk.com/api/v2/workspaces",L"application/json",json);
    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)

    // {
    //   "workspace": {
    //     "activated": "<boolean>",
    //     "apps": [
    //       {
    //         "ad_be": true,
    //         "ead07": 69455617,
    //         "adipisicinga": true
    //       },
    //       {
    //         "fugiat_e": false,
    //         "dolorf7": -57129708.70016649
    //       }
    //     ],
    //     "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": {
    //           "in_f25": true,
    //           "nisid81": "reprehenderit anim nostrud id",
    //           "minim_886": 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>"
    //       },
    //       {
    //         "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": {
    //           "culpa__d7": false,
    //           "ad7": true,
    //           "esse0": -82046233.9137964,
    //           "veniam_f": -91185504
    //         },
    //         "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>"
    //   }
    // }

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

    bool ad_be;
    int ead07;
    bool adipisicinga;
    bool fugiat_e;
    const wchar_t *dolorf7 = 0;
    const wchar_t *field = 0;
    const wchar_t *operator = 0;
    const wchar_t *value = 0;
    const wchar_t *strVal = 0;
    const wchar_t *title = 0;
    const wchar_t *active = 0;
    const wchar_t *created_at = 0;
    const wchar_t *default = 0;
    const wchar_t *description = 0;
    const wchar_t *id = 0;
    const wchar_t *position = 0;
    bool In_f25;
    const wchar_t *Nisid81 = 0;
    bool Minim_886;
    const wchar_t *updated_at = 0;
    const wchar_t *url = 0;
    const wchar_t *app_installation = 0;
    const wchar_t *categories = 0;
    const wchar_t *permissions = 0;
    const wchar_t *usage_1h = 0;
    const wchar_t *usage_7d = 0;
    const wchar_t *usage_24h = 0;
    const wchar_t *usage_30d = 0;
    bool Culpa__d7;
    bool Ad7;
    const wchar_t *Esse0 = 0;
    int Veniam_f;
    int j;
    int count_j;

    const wchar_t *Activated = jResp.stringOf(L"workspace.activated");
    const wchar_t *Created_at = jResp.stringOf(L"workspace.created_at");
    const wchar_t *Description = jResp.stringOf(L"workspace.description");
    const wchar_t *Id = jResp.stringOf(L"workspace.id");
    const wchar_t *Position = jResp.stringOf(L"workspace.position");
    const wchar_t *Prefer_workspace_app_order = jResp.stringOf(L"workspace.prefer_workspace_app_order");
    const wchar_t *Ticket_form_id = jResp.stringOf(L"workspace.ticket_form_id");
    const wchar_t *Title = jResp.stringOf(L"workspace.title");
    const wchar_t *Updated_at = jResp.stringOf(L"workspace.updated_at");
    const wchar_t *v_Url = jResp.stringOf(L"workspace.url");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"workspace.apps");
    while (i < count_i) {
        jResp.put_I(i);
        ad_be = jResp.BoolOf(L"workspace.apps[i].ad_be");
        ead07 = jResp.IntOf(L"workspace.apps[i].ead07");
        adipisicinga = jResp.BoolOf(L"workspace.apps[i].adipisicinga");
        fugiat_e = jResp.BoolOf(L"workspace.apps[i].fugiat_e");
        dolorf7 = jResp.stringOf(L"workspace.apps[i].dolorf7");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"workspace.conditions.all");
    while (i < count_i) {
        jResp.put_I(i);
        field = jResp.stringOf(L"workspace.conditions.all[i].field");
        operator = jResp.stringOf(L"workspace.conditions.all[i].operator");
        value = jResp.stringOf(L"workspace.conditions.all[i].value");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"workspace.conditions.any");
    while (i < count_i) {
        jResp.put_I(i);
        field = jResp.stringOf(L"workspace.conditions.any[i].field");
        operator = jResp.stringOf(L"workspace.conditions.any[i].operator");
        value = jResp.stringOf(L"workspace.conditions.any[i].value");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"workspace.macro_ids");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"workspace.macro_ids[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"workspace.macros");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"workspace.macros[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"workspace.selected_macros");
    while (i < count_i) {
        jResp.put_I(i);
        title = jResp.stringOf(L"workspace.selected_macros[i].title");
        active = jResp.stringOf(L"workspace.selected_macros[i].active");
        created_at = jResp.stringOf(L"workspace.selected_macros[i].created_at");
        default = jResp.stringOf(L"workspace.selected_macros[i].default");
        description = jResp.stringOf(L"workspace.selected_macros[i].description");
        id = jResp.stringOf(L"workspace.selected_macros[i].id");
        position = jResp.stringOf(L"workspace.selected_macros[i].position");
        In_f25 = jResp.BoolOf(L"workspace.selected_macros[i].restriction.in_f25");
        Nisid81 = jResp.stringOf(L"workspace.selected_macros[i].restriction.nisid81");
        Minim_886 = jResp.BoolOf(L"workspace.selected_macros[i].restriction.minim_886");
        updated_at = jResp.stringOf(L"workspace.selected_macros[i].updated_at");
        url = jResp.stringOf(L"workspace.selected_macros[i].url");
        app_installation = jResp.stringOf(L"workspace.selected_macros[i].app_installation");
        categories = jResp.stringOf(L"workspace.selected_macros[i].categories");
        permissions = jResp.stringOf(L"workspace.selected_macros[i].permissions");
        usage_1h = jResp.stringOf(L"workspace.selected_macros[i].usage_1h");
        usage_7d = jResp.stringOf(L"workspace.selected_macros[i].usage_7d");
        usage_24h = jResp.stringOf(L"workspace.selected_macros[i].usage_24h");
        usage_30d = jResp.stringOf(L"workspace.selected_macros[i].usage_30d");
        Culpa__d7 = jResp.BoolOf(L"workspace.selected_macros[i].restriction.culpa__d7");
        Ad7 = jResp.BoolOf(L"workspace.selected_macros[i].restriction.ad7");
        Esse0 = jResp.stringOf(L"workspace.selected_macros[i].restriction.esse0");
        Veniam_f = jResp.IntOf(L"workspace.selected_macros[i].restriction.veniam_f");
        j = 0;
        count_j = jResp.SizeOfArray(L"workspace.selected_macros[i].actions");
        while (j < count_j) {
            jResp.put_J(j);
            field = jResp.stringOf(L"workspace.selected_macros[i].actions[j].field");
            value = jResp.stringOf(L"workspace.selected_macros[i].actions[j].value");
            j = j + 1;
        }

        i = i + 1;
    }
    }

Curl Command

curl  -u login:password -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "workspace": {
    "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>"
        }
      ]
    },
    "description": "<string>",
    "macros": [
      "<number>",
      "<number>"
    ],
    "ticket_form_id": "<number>",
    "title": "<string>"
  }
}'
https://example.zendesk.com/api/v2/workspaces

Postman Collection Item JSON

{
  "name": "Create Workspace",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"workspace\": {\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    \"description\": \"<string>\",\n    \"macros\": [\n      \"<number>\",\n      \"<number>\"\n    ],\n    \"ticket_form_id\": \"<number>\",\n    \"title\": \"<string>\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/workspaces",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "workspaces"
      ]
    },
    "description": "#### Allowed For\n\n* Admins\n"
  },
  "response": [
    {
      "name": "Created workspace",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"workspace\": {\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    \"description\": \"<string>\",\n    \"macros\": [\n      \"<number>\",\n      \"<number>\"\n    ],\n    \"ticket_form_id\": \"<number>\",\n    \"title\": \"<string>\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/workspaces",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "workspaces"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"workspace\": {\n    \"activated\": \"<boolean>\",\n    \"apps\": [\n      {\n        \"ad_be\": true,\n        \"ead07\": 69455617,\n        \"adipisicinga\": true\n      },\n      {\n        \"fugiat_e\": false,\n        \"dolorf7\": -57129708.70016649\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          \"in_f25\": true,\n          \"nisid81\": \"reprehenderit anim nostrud id\",\n          \"minim_886\": 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        \"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          \"culpa__d7\": false,\n          \"ad7\": true,\n          \"esse0\": -82046233.9137964,\n          \"veniam_f\": -91185504\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}"
    }
  ]
}