unicodeC / Postman API / All workspaces
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *id;
const wchar_t *name;
const wchar_t *v_type;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
CkHttpW_SetRequestHeader(http,L"X-API-Key",L"{{postman_api_key}}");
sbResponseBody = CkStringBuilderW_Create();
success = CkHttpW_QuickGetSb(http,L"https://api.getpostman.com/workspaces",sbResponseBody);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpW_getLastStatus(http);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpW_lastHeader(http));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "workspaces": [
// {
// "id": "4e6d34c2-cfdb-4b33-8868-12a875bebda3",
// "name": "My Workspace",
// "type": "personal"
// },
// {
// "id": "f8801e9e-03a4-4c7b-b31e-5db5cd771696",
// "name": "Team workspace",
// "type": "team"
// }
// ]
// }
// 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.
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"workspaces");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
id = CkJsonObjectW_stringOf(jResp,L"workspaces[i].id");
name = CkJsonObjectW_stringOf(jResp,L"workspaces[i].name");
v_type = CkJsonObjectW_stringOf(jResp,L"workspaces[i].type");
i = i + 1;
}
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -X GET
-H "X-API-Key: {{postman_api_key}}"
https://api.getpostman.com/workspaces
Postman Collection Item JSON
{
"name": "All workspaces",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/workspaces",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"workspaces"
]
},
"description": "The `/workspaces` endpoint returns a list of all [workspaces](https://www.getpostman.com/docs/v6/postman/workspaces/intro_to_workspaces) that is accessible by you. The list includes your own workspaces and the workspaces that you have access to.\n\nThe response contains an array of collection information containing the `name`, `id`, and `type` of each workspace.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Valid Response",
"originalRequest": {
"method": "GET",
"header": [
],
"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 \"workspaces\": [\n {\n \"id\": \"4e6d34c2-cfdb-4b33-8868-12a875bebda3\",\n \"name\": \"My Workspace\",\n \"type\": \"personal\"\n },\n {\n \"id\": \"f8801e9e-03a4-4c7b-b31e-5db5cd771696\",\n \"name\": \"Team workspace\",\n \"type\": \"team\"\n }\n ]\n}"
}
]
}