unicodeC / Postman API / Create Workspace
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *Id;
const wchar_t *Name;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// 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": {
// "name": "New Workspace",
// "type": "personal",
// "description": "Some description",
// "collections": [
// {
// "id": "e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d",
// "name": "Straw hats",
// "uid": "8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d"
// }
// ],
// "environments": [
// {
// "id": "83a1aaa2-a204-4bd8-9b92-4d486918906b",
// "name": "env",
// "uid": "8154-83a1aaa2-a204-4bd8-9b92-4d486918906b"
// }
// ],
// "mocks": [
// {
// "id": "cda672ef-1375-40e9-baee-e20ece8d7b65"
// }
// ],
// "monitors": [
// {
// "id": "1e889bd2-3862-4be0-b2c2-9b1fe9673aec"
// }
// ]
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"workspace.name",L"New Workspace");
CkJsonObjectW_UpdateString(json,L"workspace.type",L"personal");
CkJsonObjectW_UpdateString(json,L"workspace.description",L"Some description");
CkJsonObjectW_UpdateString(json,L"workspace.collections[0].id",L"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d");
CkJsonObjectW_UpdateString(json,L"workspace.collections[0].name",L"Straw hats");
CkJsonObjectW_UpdateString(json,L"workspace.collections[0].uid",L"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d");
CkJsonObjectW_UpdateString(json,L"workspace.environments[0].id",L"83a1aaa2-a204-4bd8-9b92-4d486918906b");
CkJsonObjectW_UpdateString(json,L"workspace.environments[0].name",L"env");
CkJsonObjectW_UpdateString(json,L"workspace.environments[0].uid",L"8154-83a1aaa2-a204-4bd8-9b92-4d486918906b");
CkJsonObjectW_UpdateString(json,L"workspace.mocks[0].id",L"cda672ef-1375-40e9-baee-e20ece8d7b65");
CkJsonObjectW_UpdateString(json,L"workspace.monitors[0].id",L"1e889bd2-3862-4be0-b2c2-9b1fe9673aec");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"X-API-Key",L"{{postman_api_key}}");
resp = CkHttpW_PostJson3(http,L"https://api.getpostman.com/workspaces",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "workspace": {
// "id": "cfbcd9bf-cc8b-4d6f-b8ef-440a3e49e29f",
// "name": "New Workspace"
// }
// }
// 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.
Id = CkJsonObjectW_stringOf(jResp,L"workspace.id");
Name = CkJsonObjectW_stringOf(jResp,L"workspace.name");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -X POST
-H "X-API-Key: {{postman_api_key}}"
-H "Content-Type: application/json"
-d '{
"workspace": {
"name": "New Workspace",
"type": "personal",
"description": "Some description",
"collections": [
{
"id": "e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d",
"name": "Straw hats",
"uid": "8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d"
}
],
"environments": [
{
"id": "83a1aaa2-a204-4bd8-9b92-4d486918906b",
"name": "env",
"uid": "8154-83a1aaa2-a204-4bd8-9b92-4d486918906b"
}
],
"mocks": [
{
"id": "cda672ef-1375-40e9-baee-e20ece8d7b65"
}
],
"monitors": [
{
"id": "1e889bd2-3862-4be0-b2c2-9b1fe9673aec"
}
]
}
}'
https://api.getpostman.com/workspaces
Postman Collection Item JSON
{
"name": "Create Workspace",
"request": {
"method": "POST",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"workspace\": {\n \"name\": \"New Workspace\",\n \"type\": \"personal\",\n \"description\": \"Some description\",\n \"collections\": [\n {\n \"id\": \"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\",\n \"name\": \"Straw hats\",\n \"uid\": \"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\"\n }\n ],\n \"environments\": [\n {\n \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",\n \"name\": \"env\",\n \"uid\": \"8154-83a1aaa2-a204-4bd8-9b92-4d486918906b\"\n }\n ],\n \"mocks\": [\n {\n \"id\": \"cda672ef-1375-40e9-baee-e20ece8d7b65\"\n }\n ],\n \"monitors\": [\n {\n \"id\": \"1e889bd2-3862-4be0-b2c2-9b1fe9673aec\"\n }\n ]\n }\n}"
},
"url": {
"raw": "https://api.getpostman.com/workspaces",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"workspaces"
]
},
"description": "This endpoint allows you to create a workspace and populate it with entities like `collections`, `environments`, `mocks` and `monitors` using their `uid`.\n\nOn successful creation of the workspace, the response returns the workspcae `name` and `id`.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Successful Response",
"originalRequest": {
"method": "POST",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"workspace\": {\n \"name\": \"New Workspace\",\n \"type\": \"personal\",\n \"description\": \"Some description\",\n \"collections\": [\n {\n \"id\": \"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\",\n \"name\": \"Straw hats\",\n \"uid\": \"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\"\n }\n ],\n \"environments\": [\n {\n \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",\n \"name\": \"env\",\n \"uid\": \"8154-83a1aaa2-a204-4bd8-9b92-4d486918906b\"\n }\n ],\n \"mocks\": [\n {\n \"id\": \"cda672ef-1375-40e9-baee-e20ece8d7b65\"\n }\n ],\n \"monitors\": [\n {\n \"id\": \"1e889bd2-3862-4be0-b2c2-9b1fe9673aec\"\n }\n ]\n }\n}"
},
"url": {
"raw": "https://api.getpostman.com/workspaces",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"workspaces"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n \"workspace\": {\n \"id\": \"cfbcd9bf-cc8b-4d6f-b8ef-440a3e49e29f\",\n \"name\": \"New Workspace\"\n }\n}"
},
{
"name": "Instance supplied not found",
"originalRequest": {
"method": "POST",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"workspace\": {\n \"name\": \"New Workspace\",\n \"type\": \"personal\",\n \"description\": \"Some description\",\n \"collections\": [\n {\n \"id\": \"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\",\n \"name\": \"Straw hats\",\n \"uid\": \"8153-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\"\n }\n ],\n \"environments\": [\n {\n \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",\n \"name\": \"env\",\n \"uid\": \"8153-83a1aaa2-a204-4bd8-9b92-4d486918906b\"\n }\n ],\n \"mocks\": [\n {\n \"id\": \"dda672ef-1375-40e9-baee-e20ece8d7b65\"\n }\n ],\n \"monitors\": [\n {\n \"id\": \"2e889bd2-3862-4be0-b2c2-9b1fe9673aec\"\n }\n ]\n }\n}"
},
"url": {
"raw": "https://api.getpostman.com/workspaces",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"workspaces"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"error\": {\n \"name\": \"instanceNotFoundError\",\n \"message\": \"Instance not found in the database.\"\n }\n}"
}
]
}