Chilkat Online Tools

C / Postman API / Get environment relations

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *id;
    const char *name;
    const char *updatedAt;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttp_Create();

    CkHttp_SetRequestHeader(http,"X-API-Key","{{postman_api_key}}");

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/environment",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttp_getLastStatus(http);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttp_lastHeader(http));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

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

    // {
    //   "environment": [
    //     {
    //       "id": "2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2",
    //       "name": "C test",
    //       "updatedAt": "2019-08-29T10:18:11.000Z"
    //     },
    //     {
    //       "id": "521b0486-ab91-4d3a-9189-43c9380a0533",
    //       "name": "C1",
    //       "updatedAt": "2019-08-29T11:40:39.000Z"
    //     }
    //   ]
    // }

    // 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 = CkJsonObject_SizeOfArray(jResp,"environment");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        id = CkJsonObject_stringOf(jResp,"environment[i].id");
        name = CkJsonObject_stringOf(jResp,"environment[i].name");
        updatedAt = CkJsonObject_stringOf(jResp,"environment[i].updatedAt");
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

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

Postman Collection Item JSON

{
  "name": "Get environment relations",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "pm.test(\"Status code is 200\", function () {",
          "    pm.response.to.have.status(200);",
          "});"
        ]
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/environment",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "apis",
        "{{apiId}}",
        "versions",
        "{{apiVersionId}}",
        "environment"
      ]
    },
    "description": "This call fetches all the relations by type which are linked to the specified API version along with their details.\n\nThe response will contain an array with key `{{relationType}}`. Each of the item will consist of all the details related each of the relation.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
    {
      "name": "Get environment relations",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/relations/environment",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "apis",
            "{{apiId}}",
            "versions",
            "{{apiVersionId}}",
            "relations",
            "environment"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "description": {
            "content": "",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"environment\": [\n        {\n            \"id\": \"2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2\",\n            \"name\": \"C test\",\n            \"updatedAt\": \"2019-08-29T10:18:11.000Z\"\n        },\n        {\n            \"id\": \"521b0486-ab91-4d3a-9189-43c9380a0533\",\n            \"name\": \"C1\",\n            \"updatedAt\": \"2019-08-29T11:40:39.000Z\"\n        }\n    ]\n}"
    }
  ]
}