Chilkat Online Tools

SQL Server / Postman API / Get All API Versions

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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.getpostman.com/apis/{{apiId}}/versions', @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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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)

    -- {
    --   "versions": [
    --     {
    --       "id": "024660a6-c837-46ca-91d8-7e8dd7c669de",
    --       "name": "0.1",
    --       "summary": "Summary",
    --       "description": "Description",
    --       "createdBy": "5665",
    --       "createdAt": "2019-02-12 19:34:49",
    --       "updatedAt": "2019-02-12 19:34:49"
    --     },
    --     {
    --       "id": "00932d3b-20f1-454f-a77e-38b4023163ea",
    --       "name": "0.2",
    --       "summary": "Summary",
    --       "description": "Description",
    --       "createdBy": "5665",
    --       "createdAt": "2019-02-12 19:34:49",
    --       "updatedAt": "2019-02-12 19:34:49"
    --     }
    --   ]
    -- }

    -- 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)

    DECLARE @name nvarchar(4000)

    DECLARE @summary nvarchar(4000)

    DECLARE @description nvarchar(4000)

    DECLARE @createdBy nvarchar(4000)

    DECLARE @createdAt nvarchar(4000)

    DECLARE @updatedAt nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'versions'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'versions[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'versions[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @summary OUT, 'versions[i].summary'
        EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'versions[i].description'
        EXEC sp_OAMethod @jResp, 'StringOf', @createdBy OUT, 'versions[i].createdBy'
        EXEC sp_OAMethod @jResp, 'StringOf', @createdAt OUT, 'versions[i].createdAt'
        EXEC sp_OAMethod @jResp, 'StringOf', @updatedAt OUT, 'versions[i].updatedAt'
        SELECT @i = @i + 1
      END

    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

Postman Collection Item JSON

{
  "name": "Get All API Versions",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.getpostman.com/apis/{{apiId}}/versions",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "apis",
        "{{apiId}}",
        "versions"
      ]
    },
    "description": "This call fetches details about the all the API Versions in the specified API.\n\nThe response will contain an array `versions` object which would be a list of all the API Version along with their details.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
    {
      "name": "Get All API versions",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "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\"versions\": [\n\t\t{\n\t      \"id\": \"024660a6-c837-46ca-91d8-7e8dd7c669de\",\n\t      \"name\": \"0.1\",\n\t      \"summary\": \"Summary\",\n\t      \"description\": \"Description\",\n\t      \"createdBy\": \"5665\",\n\t      \"createdAt\": \"2019-02-12 19:34:49\",\n\t      \"updatedAt\": \"2019-02-12 19:34:49\"\n\t    },\n\t    {\n\t      \"id\": \"00932d3b-20f1-454f-a77e-38b4023163ea\",\n\t      \"name\": \"0.2\",\n\t      \"summary\": \"Summary\",\n\t      \"description\": \"Description\",\n\t      \"createdBy\": \"5665\",\n\t      \"createdAt\": \"2019-02-12 19:34:49\",\n\t      \"updatedAt\": \"2019-02-12 19:34:49\"\n\t    }\n\t]\n}"
    }
  ]
}