SQL Server / Postman API / Get Schema
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-API-Key', '{{postman_api_key}}'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/schemas/{{schemaId}}', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "schema": {
-- "id": "e3b3a0b7-34d5-4fc5-83e0-118bd9e8c822",
-- "language": "json",
-- "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",
-- "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}"
-- }
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @Id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'schema.id'
DECLARE @Language nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Language OUT, 'schema.language'
DECLARE @ApiVersion nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @ApiVersion OUT, 'schema.apiVersion'
DECLARE @v_Type nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'schema.type'
DECLARE @CreatedBy nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @CreatedBy OUT, 'schema.createdBy'
DECLARE @UpdatedBy nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @UpdatedBy OUT, 'schema.updatedBy'
DECLARE @CreatedAt nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @CreatedAt OUT, 'schema.createdAt'
DECLARE @UpdatedAt nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @UpdatedAt OUT, 'schema.updatedAt'
DECLARE @Schema nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Schema OUT, 'schema.schema'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X GET
-H "X-API-Key: {{postman_api_key}}"
https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/schemas/{{schemaId}}
Postman Collection Item JSON
{
"name": "Get Schema",
"request": {
"method": "GET",
"header": [
],
"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 fetches a single schema having the specified id.\n\nResponse contains a `schema` object with all the details related to the schema, namely, `id`, `language`, `type`, `schema` etc. \n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Get schema",
"originalRequest": {
"method": "GET",
"header": [
],
"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}}"
]
}
},
"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\": \"json\",\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 \"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}\n}"
}
]
}