ERROR!
------------------- GenerateCode ----------------------
ImpliedContentType: application/json
explicitContentType: application/json
---- begin chilkat script ----
// This example assumes the Chilkat API to have been previously unlocked.
// See {{-global_unlock:::Global Unlock Sample-}} for sample code.
new Http http;
ckbool success;
// Use this online tool to generate code from sample JSON: {{.https://tools.chilkat.io/jsonCreate|||Generate Code to Create JSON.}}
// The following JSON is sent in the request body.
// {
// "schema": {
// "language": "json",
// "schema": "{\n \"openapi\": \"3.0.0\",\n \"info\": null,\n \"version\": \"v1.0\",\n \"title\": \"API\",\n \"servers\": [\n {\n \"url\": \"http:\/\/localhost:3000\"\n }\n ],\n \"paths\": {\n \"\/user\": {\n \"get\": {\n \"summary\": \"Returns details about a particular user\",\n \"operationId\": \"listUser\",\n \"tags\": [\n \"user\"\n ],\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"description\": \"ID of the user\",\n \"required\": true,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Details about a user by ID\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application\/json\": {\n \"schema\": {\n \"$ref\": \"\\\\'#\/components\/schemas\/User\\\\'\"\n }\n }\n }\n },\n \"default\": {\n \"description\": \"Unexpected error\",\n \"content\": {\n \"application\/json\": {\n \"schema\": {\n \"$ref\": \"\\\\'#\/components\/schemas\/Error\\\\'\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}",
// "type": "openapi3"
// }
// }
new JsonObject json;
ignore = json.UpdateString("schema.language","json");
ignore = json.UpdateString("schema.schema","{\n \"openapi\": \"3.0.0\",\n \"info\": null,\n \"version\": \"v1.0\",\n \"title\": \"API\",\n \"servers\": [\n {\n \"url\": \"http://localhost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"Returns details about a particular user\",\n \"operationId\": \"listUser\",\n \"tags\": [\n \"user\"\n ],\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"description\": \"ID of the user\",\n \"required\": true,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Details about a user by ID\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"\#/components/schemas/User\\"\n }\n }\n }\n },\n \"default\": {\n \"description\": \"Unexpected error\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"\#/components/schemas/Error\\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}");
ignore = json.UpdateString("schema.type","openapi3");
call http.SetRequestHeader("Content-Type","application/json");
call http.SetRequestHeader("X-API-Key","{{postman_api_key}}");
new StringBuilder sbRequestBody;
call json.EmitSb(sbRequestBody);
HttpResponse resp = http.PTextSb("PUT","https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/schemas/{{schemaId}}",sbRequestBody,"utf-8","application/json",ckfalse,ckfalse);
if (http.LastMethodSuccess == ckfalse) {
println http.LastErrorText;
return;
}
new StringBuilder sbResponseBody;
ignore = resp.GetBodySb(sbResponseBody);
new JsonObject jResp;
call jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = ckfalse;
println "Response Body:";
println jResp.Emit();
int respStatusCode = resp.StatusCode;
println "Response Status Code = ",respStatusCode;
if (respStatusCode >= 400) {
println "Response Header:";
println resp.Header;
println "Failed.";
delete resp;
return;
}
delete resp;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "schema": {
// "id": "e3b3a0b7-34d5-4fc5-83e0-118bd9e8c822",
// "language": "yaml",
// "apiVersion": "ad810c39-df60-434e-a76f-a2192cd8d81f",
// "type": "openapi3",
// "createdBy": "5665",
// "updatedBy": "5665",
// "createdAt": "2021-05-22T13:17:07.000Z",
// "updatedAt": "2021-05-22T13:17:07.000Z"
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: {{.https://tools.chilkat.io/jsonParse|||Generate JSON Parsing Code.}}
#ifdef IS_C_CPP
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
#undef IS_C_CPP
string Id = jResp.StringOf("schema.id");
string Language = jResp.StringOf("schema.language");
string ApiVersion = jResp.StringOf("schema.apiVersion");
string v_Type = jResp.StringOf("schema.type");
string CreatedBy = jResp.StringOf("schema.createdBy");
string UpdatedBy = jResp.StringOf("schema.updatedBy");
string CreatedAt = jResp.StringOf("schema.createdAt");
string UpdatedAt = jResp.StringOf("schema.updatedAt");
---- end chilkat script ----
unicodeC / Postman API / Update Schema
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
// 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.
// {
// "schema": {
// "language": "json",
// "schema": "{\n \"openapi\": \"3.0.0\",\n \"info\": null,\n \"version\": \"v1.0\",\n \"title\": \"API\",\n \"servers\": [\n {\n \"url\": \"http:\/\/localhost:3000\"\n }\n ],\n \"paths\": {\n \"\/user\": {\n \"get\": {\n \"summary\": \"Returns details about a particular user\",\n \"operationId\": \"listUser\",\n \"tags\": [\n \"user\"\n ],\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"description\": \"ID of the user\",\n \"required\": true,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Details about a user by ID\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application\/json\": {\n \"schema\": {\n \"$ref\": \"\\\\'#\/components\/schemas\/User\\\\'\"\n }\n }\n }\n },\n \"default\": {\n \"description\": \"Unexpected error\",\n \"content\": {\n \"application\/json\": {\n \"schema\": {\n \"$ref\": \"\\\\'#\/components\/schemas\/Error\\\\'\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}",
// "type": "openapi3"
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"schema.language",L"json");
ERROR: ")" expected
CkJsonObjectW_UpdateString(json,L"schema.schema",L"{\n \"openapi\": \"3.0.0\",\n \"info\": null,\n \"version\": \"v1.0\",\n \"title\": \"API\",\n \"servers\": [\n {\n \"url\": \"http://localhost:3000\"\n }\n ],\n \"paths\": {\n \"/user\": {\n \"get\": {\n \"summary\": \"Returns details about a particular user\",\n \"operationId\": \"listUser\",\n \"tags\": [\n \"user\"\n ],\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"description\": \"ID of the user\",\n \"required\": true,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Details about a user by ID\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"\#/components/schemas/User\\");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
}
Curl Command
curl -X PUT
-H "X-API-Key: {{postman_api_key}}"
-H "Content-Type: application/json"
-d '{
"schema": {
"language": "json",
"schema": "{\n \"openapi\": \"3.0.0\",\n \"info\": null,\n \"version\": \"v1.0\",\n \"title\": \"API\",\n \"servers\": [\n {\n \"url\": \"http:\/\/localhost:3000\"\n }\n ],\n \"paths\": {\n \"\/user\": {\n \"get\": {\n \"summary\": \"Returns details about a particular user\",\n \"operationId\": \"listUser\",\n \"tags\": [\n \"user\"\n ],\n \"parameters\": [\n {\n \"name\": \"id\",\n \"in\": \"query\",\n \"description\": \"ID of the user\",\n \"required\": true,\n \"schema\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n }\n }\n ],\n \"responses\": {\n \"200\": {\n \"description\": \"Details about a user by ID\",\n \"headers\": {\n \"x-next\": {\n \"description\": \"A link to the next page of responses\",\n \"schema\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"application\/json\": {\n \"schema\": {\n \"$ref\": \"\\\\\'#\/components\/schemas\/User\\\\\'\"\n }\n }\n }\n },\n \"default\": {\n \"description\": \"Unexpected error\",\n \"content\": {\n \"application\/json\": {\n \"schema\": {\n \"$ref\": \"\\\\\'#\/components\/schemas\/Error\\\\\'\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"User\": {\n \"type\": \"object\",\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"type\": \"object\",\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}",
"type": "openapi3"
}
}'
https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/schemas/{{schemaId}}
Postman Collection Item JSON
{
"name": "Update Schema",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"const schema = {",
" \"openapi\": \"3.0.0\",",
" \"info\": null,",
" \"version\": \"v1.0\",",
" \"title\": \"API\",",
" \"servers\": [",
" {",
" \"url\": \"http://localhost:3000\"",
" }",
" ],",
" \"paths\": {",
" \"/user\": {",
" \"get\": {",
" \"summary\": \"Returns details about a particular user\",",
" \"operationId\": \"listUser\",",
" \"tags\": [",
" \"user\"",
" ],",
" \"parameters\": [",
" {",
" \"name\": \"id\",",
" \"in\": \"query\",",
" \"description\": \"ID of the user\",",
" \"required\": true,",
" \"schema\": {",
" \"type\": \"integer\",",
" \"format\": \"int32\"",
" }",
" }",
" ],",
" \"responses\": {",
" \"200\": {",
" \"description\": \"Details about a user by ID\",",
" \"headers\": {",
" \"x-next\": {",
" \"description\": \"A link to the next page of responses\",",
" \"schema\": {",
" \"type\": \"string\"",
" }",
" }",
" },",
" \"content\": {",
" \"application/json\": {",
" \"schema\": {",
" \"$ref\": \"\\\\'#/components/schemas/User\\\\'\"",
" }",
" }",
" }",
" },",
" \"default\": {",
" \"description\": \"Unexpected error\",",
" \"content\": {",
" \"application/json\": {",
" \"schema\": {",
" \"$ref\": \"\\\\'#/components/schemas/Error\\\\'\"",
" }",
" }",
" }",
" }",
" }",
" }",
" }",
" },",
" \"components\": {",
" \"schemas\": {",
" \"User\": {",
" \"type\": \"object\",",
" \"required\": [",
" \"id\",",
" \"name\"",
" ],",
" \"properties\": {",
" \"id\": {",
" \"type\": \"integer\",",
" \"format\": \"int64\"",
" },",
" \"name\": {",
" \"type\": \"string\"",
" },",
" \"tag\": {",
" \"type\": \"string\"",
" }",
" }",
" },",
" \"Error\": {",
" \"type\": \"object\",",
" \"required\": [",
" \"code\",",
" \"message\"",
" ],",
" \"properties\": {",
" \"code\": {",
" \"type\": \"integer\",",
" \"format\": \"int32\"",
" },",
" \"message\": {",
" \"type\": \"string\"",
" }",
" }",
" }",
" }",
" }",
"};",
"",
"pm.environment.set('schema', JSON.stringify(JSON.stringify(schema)));"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"schema\": {\n\t\t\"language\": \"json\",\n\t\t\"schema\": \"{\\n \\\"openapi\\\": \\\"3.0.0\\\",\\n \\\"info\\\": null,\\n \\\"version\\\": \\\"v1.0\\\",\\n \\\"title\\\": \\\"API\\\",\\n \\\"servers\\\": [\\n {\\n \\\"url\\\": \\\"http:\\/\\/localhost:3000\\\"\\n }\\n ],\\n \\\"paths\\\": {\\n \\\"\\/user\\\": {\\n \\\"get\\\": {\\n \\\"summary\\\": \\\"Returns details about a particular user\\\",\\n \\\"operationId\\\": \\\"listUser\\\",\\n \\\"tags\\\": [\\n \\\"user\\\"\\n ],\\n \\\"parameters\\\": [\\n {\\n \\\"name\\\": \\\"id\\\",\\n \\\"in\\\": \\\"query\\\",\\n \\\"description\\\": \\\"ID of the user\\\",\\n \\\"required\\\": true,\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"integer\\\",\\n \\\"format\\\": \\\"int32\\\"\\n }\\n }\\n ],\\n \\\"responses\\\": {\\n \\\"200\\\": {\\n \\\"description\\\": \\\"Details about a user by ID\\\",\\n \\\"headers\\\": {\\n \\\"x-next\\\": {\\n \\\"description\\\": \\\"A link to the next page of responses\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n }\\n },\\n \\\"content\\\": {\\n \\\"application\\/json\\\": {\\n \\\"schema\\\": {\\n \\\"$ref\\\": \\\"\\\\\\\\'#\\/components\\/schemas\\/User\\\\\\\\'\\\"\\n }\\n }\\n }\\n },\\n \\\"default\\\": {\\n \\\"description\\\": \\\"Unexpected error\\\",\\n \\\"content\\\": {\\n \\\"application\\/json\\\": {\\n \\\"schema\\\": {\\n \\\"$ref\\\": \\\"\\\\\\\\'#\\/components\\/schemas\\/Error\\\\\\\\'\\\"\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n },\\n \\\"components\\\": {\\n \\\"schemas\\\": {\\n \\\"User\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"required\\\": [\\n \\\"id\\\",\\n \\\"name\\\"\\n ],\\n \\\"properties\\\": {\\n \\\"id\\\": {\\n \\\"type\\\": \\\"integer\\\",\\n \\\"format\\\": \\\"int64\\\"\\n },\\n \\\"name\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"tag\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n }\\n },\\n \\\"Error\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"required\\\": [\\n \\\"code\\\",\\n \\\"message\\\"\\n ],\\n \\\"properties\\\": {\\n \\\"code\\\": {\\n \\\"type\\\": \\\"integer\\\",\\n \\\"format\\\": \\\"int32\\\"\\n },\\n \\\"message\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n }\\n }\\n }\\n }\\n}\",\n\t\t\"type\": \"openapi3\"\n\t}\n}"
},
"url": {
"raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/schemas/{{schemaId}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"apis",
"{{apiId}}",
"versions",
"{{apiVersionId}}",
"schemas",
"{{schemaId}}"
]
},
"description": "This call updates an existing schema.\n\nRequest body should contain a `schema` object which should atleast have these properties with `string` values:\n\n- **`type`**: Allowed types are `openapi3`, `openapi2`, `openapi1`, `raml` and `graphql`.\n- **`language`** : Allowed languages are `json` and `yaml` for OpenAPI and RAML schema types. GraphQL schema type accepts only `graphql` language.\n- **`schema`**: Optional. If passed, must be the content of the schema as a `string`.\n\nResponse contains a `schema` object with all the details related to the created schema, namely, `id`, `language`, `type` etc. \n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Update schema",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"schema\": {\n \"language\": \"yaml\",\n \"schema\": \"openapi: \\\"3.0.0\\\"↵info:↵ version: 1.0.0↵ title: Swagger Petstore↵ license:↵ name: MIT↵servers:↵ - url: http://petstore.swagger.io/v1↵paths:↵ /pets:↵ get:↵ summary: List all pets↵ operationId: listPets↵ tags:↵ - pets↵ parameters:↵ - name: limit↵ in: query↵ description: How many items to return at one time (max 100)↵ required: false↵ schema:↵ type: integer↵ format: int32↵ responses:↵ 200:↵ description: An paged array of pets↵ headers:↵ x-next:↵ description: A link to the next page of responses↵ schema:↵ type: string↵ content:↵ application/json: ↵ schema:↵ $ref: \\\"#/components/schemas/Pets\\\"↵ default:↵ description: unexpected error↵ content:↵ application/json:↵ schema:↵ $ref: \\\"#/components/schemas/Error\\\"↵ post:↵ summary: Create a pet↵ operationId: createPets↵ tags:↵ - pets↵ responses:↵ 201:↵ description: Null response↵ default:↵ description: unexpected error↵ content:↵ application/json:↵ schema:↵ $ref: \\\"#/components/schemas/Error\\\"\",\n \"type\": \"openapi3\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{versionId}}/schemas/{{schemaId}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"apis",
"{{apiId}}",
"versions",
"{{versionId}}",
"schemas",
"{{schemaId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n\t\"schema\": {\n\t\t\"id\": \"e3b3a0b7-34d5-4fc5-83e0-118bd9e8c822\",\n\t\t\"language\": \"yaml\",\n\t\t\"apiVersion\": \"ad810c39-df60-434e-a76f-a2192cd8d81f\",\n\t\t\"type\": \"openapi3\",\n\t\t\"createdBy\": \"5665\",\n \"updatedBy\": \"5665\",\n\t\t\"createdAt\": \"2021-05-22T13:17:07.000Z\",\n\t\t\"updatedAt\": \"2021-05-22T13:17:07.000Z\"\n\t}\n}"
}
]
}