Chilkat Online Tools

unicodeCpp / Postman API / Get All API Versions

Back to Collection Items

#include <CkHttpW.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.SetRequestHeader(L"X-API-Key",L"{{postman_api_key}}");

    CkStringBuilderW sbResponseBody;
    success = http.QuickGetSb(L"https://api.getpostman.com/apis/{{apiId}}/versions",sbResponseBody);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = http.get_LastStatus();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",http.lastHeader());
        wprintf(L"Failed.\n");
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "versions": [
    //     {
    //       "id": "024660a6-c837-46ca-91d8-7e8dd7c669de",
    //       "name": "0.1",
    //       "summary": "Summary",
    //       "description": "Description",
    //       "createdBy": "5665",
    //       "createdAt": "2019-02-12 19:34:49",
    //       "updatedAt": "2019-02-12 19:34:49"
    //     },
    //     {
    //       "id": "00932d3b-20f1-454f-a77e-38b4023163ea",
    //       "name": "0.2",
    //       "summary": "Summary",
    //       "description": "Description",
    //       "createdBy": "5665",
    //       "createdAt": "2019-02-12 19:34:49",
    //       "updatedAt": "2019-02-12 19:34:49"
    //     }
    //   ]
    // }

    // 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 *id = 0;
    const wchar_t *name = 0;
    const wchar_t *summary = 0;
    const wchar_t *description = 0;
    const wchar_t *createdBy = 0;
    const wchar_t *createdAt = 0;
    const wchar_t *updatedAt = 0;

    int i = 0;
    int count_i = jResp.SizeOfArray(L"versions");
    while (i < count_i) {
        jResp.put_I(i);
        id = jResp.stringOf(L"versions[i].id");
        name = jResp.stringOf(L"versions[i].name");
        summary = jResp.stringOf(L"versions[i].summary");
        description = jResp.stringOf(L"versions[i].description");
        createdBy = jResp.stringOf(L"versions[i].createdBy");
        createdAt = jResp.stringOf(L"versions[i].createdAt");
        updatedAt = jResp.stringOf(L"versions[i].updatedAt");
        i = i + 1;
    }
    }

Curl Command

curl -X GET
	-H "X-API-Key: {{postman_api_key}}"
https://api.getpostman.com/apis/{{apiId}}/versions

Postman Collection Item JSON

{
  "name": "Get All API Versions",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.getpostman.com/apis/{{apiId}}/versions",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "apis",
        "{{apiId}}",
        "versions"
      ]
    },
    "description": "This call fetches details about the all the API Versions in the specified API.\n\nThe response will contain an array `versions` object which would be a list of all the API Version along with their details.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
    {
      "name": "Get All API versions",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/apis/{{apiId}}/versions",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "apis",
            "{{apiId}}",
            "versions"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "description": {
            "content": "",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"versions\": [\n\t\t{\n\t      \"id\": \"024660a6-c837-46ca-91d8-7e8dd7c669de\",\n\t      \"name\": \"0.1\",\n\t      \"summary\": \"Summary\",\n\t      \"description\": \"Description\",\n\t      \"createdBy\": \"5665\",\n\t      \"createdAt\": \"2019-02-12 19:34:49\",\n\t      \"updatedAt\": \"2019-02-12 19:34:49\"\n\t    },\n\t    {\n\t      \"id\": \"00932d3b-20f1-454f-a77e-38b4023163ea\",\n\t      \"name\": \"0.2\",\n\t      \"summary\": \"Summary\",\n\t      \"description\": \"Description\",\n\t      \"createdBy\": \"5665\",\n\t      \"createdAt\": \"2019-02-12 19:34:49\",\n\t      \"updatedAt\": \"2019-02-12 19:34:49\"\n\t    }\n\t]\n}"
    }
  ]
}