Chilkat Online Tools

Objective-C / Postman API / Get documentation relations

Back to Collection Items

#import <CkoHttp.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

[http SetRequestHeader: @"X-API-Key" value: @"{{postman_api_key}}"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [http QuickGetSb: @"https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/documentation" sbContent: sbResponseBody];
if (success == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [http.LastStatus intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",http.LastHeader);
    NSLog(@"%@",@"Failed.");
    return;
}

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

// {
//   "documentation": [
//     {
//       "id": "2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2",
//       "name": "C test",
//       "updatedAt": "2019-08-29T10:18:11.000Z",
//       "collectionId": "7732157-a8bcd149-2b01-4b4c-8c14-c7d05be77745"
//     },
//     {
//       "id": "521b0486-ab91-4d3a-9189-43c9380a0533",
//       "name": "C1",
//       "updatedAt": "2019-08-29T11:40:39.000Z",
//       "collectionId": "7332157-a8bcd143-2b01-4b12-8c14-c7d05be77725"
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

NSString *id = 0;
NSString *name = 0;
NSString *updatedAt = 0;
NSString *collectionId = 0;

int i = 0;
int count_i = [[jResp SizeOfArray: @"documentation"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    id = [jResp StringOf: @"documentation[i].id"];
    name = [jResp StringOf: @"documentation[i].name"];
    updatedAt = [jResp StringOf: @"documentation[i].updatedAt"];
    collectionId = [jResp StringOf: @"documentation[i].collectionId"];
    i = i + 1;
}

Curl Command

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

Postman Collection Item JSON

{
  "name": "Get  documentation 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}}/documentation",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "apis",
        "{{apiId}}",
        "versions",
        "{{apiVersionId}}",
        "documentation"
      ]
    },
    "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 documentation relations",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/relations/documentation",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "apis",
            "{{apiId}}",
            "versions",
            "{{apiVersionId}}",
            "relations",
            "documentation"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "description": {
            "content": "",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"documentation\": [\n        {\n            \"id\": \"2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2\",\n            \"name\": \"C test\",\n            \"updatedAt\": \"2019-08-29T10:18:11.000Z\",\n            \"collectionId\": \"7732157-a8bcd149-2b01-4b4c-8c14-c7d05be77745\"\n        },\n        {\n            \"id\": \"521b0486-ab91-4d3a-9189-43c9380a0533\",\n            \"name\": \"C1\",\n            \"updatedAt\": \"2019-08-29T11:40:39.000Z\",\n            \"collectionId\": \"7332157-a8bcd143-2b01-4b12-8c14-c7d05be77725\"\n        }\n    ]\n}"
    }
  ]
}