unicodeC / Postman API / All Mocks
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 *owner;
const wchar_t *uid;
const wchar_t *collection;
const wchar_t *environment;
const wchar_t *mockUrl;
const wchar_t *name;
BOOL MatchBody;
BOOL MatchQueryParams;
BOOL MatchWildcards;
const wchar_t *Delay;
const wchar_t *createdAt;
const wchar_t *updatedAt;
BOOL isPublic;
int j;
int count_j;
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/mocks",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)
// {
// "mocks": [
// {
// "id": "e782b64e-406b-4a6c-8fe9-9ebe84aeb706",
// "owner": "1686168",
// "uid": "1686168-e782b64e-406b-4a6c-8fe9-9ebe84aeb706",
// "collection": "1686168-39fee52f-b806-3ffa-1173-00a6f5b183dc",
// "environment": "1686168-2b90cdd8-e9ac-4086-91c2-bc4cad659511",
// "mockUrl": "https://e782b64e-406b-4a6c-8fe9-9ebe84aeb706.mock.pstmn.io",
// "name": "mock1",
// "config": {
// "headers": [
// ],
// "matchBody": false,
// "matchQueryParams": true,
// "matchWildcards": true,
// "delay": null
// },
// "createdAt": "2020-12-15T06:44:37.000Z",
// "updatedAt": "2020-12-15T06:44:37.000Z",
// "isPublic": false
// },
// {
// "id": "8f9d4b95-780d-455d-af38-772277bc9393",
// "owner": "1686168",
// "uid": "1686168-8f9d4b95-780d-455d-af38-772277bc9393",
// "collection": "1686168-37eeb72f-5d3e-48b4-8022-6b9cca6d2664",
// "mockUrl": "https://8f9d4b95-780d-455d-af38-772277bc93936.mock.pstmn.io",
// "name": "mock2",
// "config": {
// "headers": [
// ],
// "matchBody": false,
// "matchQueryParams": true,
// "matchWildcards": true,
// "delay": null
// },
// "createdAt": "2020-11-15T06:44:37.000Z",
// "updatedAt": "2020-12-15T06:48:37.000Z",
// "isPublic": true
// }
// ]
// }
// 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"mocks");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
id = CkJsonObjectW_stringOf(jResp,L"mocks[i].id");
owner = CkJsonObjectW_stringOf(jResp,L"mocks[i].owner");
uid = CkJsonObjectW_stringOf(jResp,L"mocks[i].uid");
collection = CkJsonObjectW_stringOf(jResp,L"mocks[i].collection");
environment = CkJsonObjectW_stringOf(jResp,L"mocks[i].environment");
mockUrl = CkJsonObjectW_stringOf(jResp,L"mocks[i].mockUrl");
name = CkJsonObjectW_stringOf(jResp,L"mocks[i].name");
MatchBody = CkJsonObjectW_BoolOf(jResp,L"mocks[i].config.matchBody");
MatchQueryParams = CkJsonObjectW_BoolOf(jResp,L"mocks[i].config.matchQueryParams");
MatchWildcards = CkJsonObjectW_BoolOf(jResp,L"mocks[i].config.matchWildcards");
Delay = CkJsonObjectW_stringOf(jResp,L"mocks[i].config.delay");
createdAt = CkJsonObjectW_stringOf(jResp,L"mocks[i].createdAt");
updatedAt = CkJsonObjectW_stringOf(jResp,L"mocks[i].updatedAt");
isPublic = CkJsonObjectW_BoolOf(jResp,L"mocks[i].isPublic");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"mocks[i].config.headers");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
j = j + 1;
}
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/mocks
Postman Collection Item JSON
{
"name": "All Mocks",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/mocks",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"mocks"
]
},
"description": "This endpoint fetches all the mocks that you have created.\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": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/mocks",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"mocks"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"name": "Content-Type",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n \"mocks\": [\n {\n \"id\": \"e782b64e-406b-4a6c-8fe9-9ebe84aeb706\",\n \"owner\": \"1686168\",\n \"uid\": \"1686168-e782b64e-406b-4a6c-8fe9-9ebe84aeb706\",\n \"collection\": \"1686168-39fee52f-b806-3ffa-1173-00a6f5b183dc\",\n \"environment\": \"1686168-2b90cdd8-e9ac-4086-91c2-bc4cad659511\",\n \"mockUrl\": \"https://e782b64e-406b-4a6c-8fe9-9ebe84aeb706.mock.pstmn.io\",\n \"name\": \"mock1\",\n \"config\": {\n \"headers\": [],\n \"matchBody\": false,\n \"matchQueryParams\": true,\n \"matchWildcards\": true,\n \"delay\": null\n },\n \"createdAt\": \"2020-12-15T06:44:37.000Z\",\n \"updatedAt\": \"2020-12-15T06:44:37.000Z\",\n \"isPublic\": false\n },\n {\n \"id\": \"8f9d4b95-780d-455d-af38-772277bc9393\",\n \"owner\": \"1686168\",\n \"uid\": \"1686168-8f9d4b95-780d-455d-af38-772277bc9393\",\n \"collection\": \"1686168-37eeb72f-5d3e-48b4-8022-6b9cca6d2664\",\n \"mockUrl\": \"https://8f9d4b95-780d-455d-af38-772277bc93936.mock.pstmn.io\",\n \"name\": \"mock2\",\n \"config\": {\n \"headers\": [],\n \"matchBody\": false,\n \"matchQueryParams\": true,\n \"matchWildcards\": true,\n \"delay\": null\n },\n \"createdAt\": \"2020-11-15T06:44:37.000Z\",\n \"updatedAt\": \"2020-12-15T06:48:37.000Z\",\n \"isPublic\": true\n }\n ]\n}"
}
]
}