unicodeC / Postman API / Create API Version
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *Id;
const wchar_t *Name;
const wchar_t *Api;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "version": {
// "name": "1.0",
// "source": {
// "id": "{{apiVersionId}}",
// "schema": true,
// "relations": {
// "monitor": true,
// "mock": true,
// "documentation": true
// }
// }
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"version.name",L"1.0");
CkJsonObjectW_UpdateString(json,L"version.source.id",L"{{apiVersionId}}");
CkJsonObjectW_UpdateBool(json,L"version.source.schema",TRUE);
CkJsonObjectW_UpdateBool(json,L"version.source.relations.monitor",TRUE);
CkJsonObjectW_UpdateBool(json,L"version.source.relations.mock",TRUE);
CkJsonObjectW_UpdateBool(json,L"version.source.relations.documentation",TRUE);
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"X-API-Key",L"{{postman_api_key}}");
resp = CkHttpW_PostJson3(http,L"https://api.getpostman.com/apis/{{apiId}}/versions",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "version": {
// "id": "d71cf403-c549-4c7c-9dc6-a6a105acf67c",
// "name": "1.0",
// "api": "2b95d07c-8379-4bd1-924f-e7e1af185284"
// }
// }
// 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.
Id = CkJsonObjectW_stringOf(jResp,L"version.id");
Name = CkJsonObjectW_stringOf(jResp,L"version.name");
Api = CkJsonObjectW_stringOf(jResp,L"version.api");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}
Curl Command
curl -X POST
-H "X-API-Key: {{postman_api_key}}"
-H "Content-Type: application/json"
-d '{
"version": {
"name": "1.0",
"source": {
"id": "{{apiVersionId}}",
"schema": true,
"relations": {
"monitor": true,
"mock": true,
"documentation": true
}
}
}
}'
https://api.getpostman.com/apis/{{apiId}}/versions
Postman Collection Item JSON
{
"name": "Create API Version",
"request": {
"method": "POST",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"version\": {\n\t\t\"name\": \"1.0\",\n\t\t\"source\": {\n\t\t\t\"id\": \"{{apiVersionId}}\",\n\t\t\t\"schema\": true,\n\t\t\t\"relations\": {\n\t\t\t\t\"monitor\": true,\n\t\t\t\t\"mock\": true,\n\t\t\t\t\"documentation\": true\n\t\t\t}\n\t\t}\n\t}\n}"
},
"url": {
"raw": "https://api.getpostman.com/apis/{{apiId}}/versions",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"apis",
"{{apiId}}",
"versions"
]
},
"description": "This call creates a new API version in the specified API. \n\nRequest body should contain a `version` object which should have fields:\n\n<table>\n<tr>\n\t<td>name</td>\n\t<td>Required. Name of the API Version</td>\n</tr>\n<tr>\n\t<td>source</td>\n\t<td>\n\t\tIf specified, it will copy the contents of the specified api version to create a new api verison.\n\t\t<table>\n\t\t\t<tr>\n\t\t\t\t<td>id</td>\n\t\t\t\t<td>Required. Id of the apiversion from where the details are to be copied</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>schema</td>\n\t\t\t\t<td>Boolean. If true then copies the schema from the specified api version</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>relations</td>\n\t\t\t\t<td>Object. {\"<relationType>\": true/false}. \n\t\t\t\t\tAllowed relation types are `mock`, `monitor`, `documentation`, `contracttest`, `integrationtest`, `testsuite`, `environment`\n\t\t\t\tRelation types which should be copied over to the new api verison</td>\n\t\t\t</tr>\n\t\t</table>\n\t</td>\n</tr>\n</table>\n\nResponse contains a `version` object with all the details related to the created API Version, namely, `id`, `name`, `api`.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Create API version",
"originalRequest": {
"method": "POST",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"version\": {\n\t\t\"name\": \"1.0\",\n\t\t\"source\": {\n\t\t\t\"id\": \"{{apiVersionId}}\",\n\t\t\t\"schema\": true,\n\t\t\t\"relations\": {\n\t\t\t\t\"monitor\": true,\n\t\t\t\t\"mock\": true,\n\t\t\t\t\"documentation\": true\n\t\t\t}\n\t\t}\n\t}\n}"
},
"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\"version\": {\n\t\t\"id\": \"d71cf403-c549-4c7c-9dc6-a6a105acf67c\",\n\t\t\"name\": \"1.0\",\n \t\"api\": \"2b95d07c-8379-4bd1-924f-e7e1af185284\"\n\t}\n}"
}
]
}