Chilkat Online Tools

SQL Server / Postman API / Get linked relations

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}}/relations', @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)

    -- {
    --   "relations": {
    --     "contracttest": {
    --       "2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2": {
    --         "id": "2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2",
    --         "name": "C test",
    --         "updatedAt": "2019-08-29T10:18:11.000Z"
    --       }
    --     },
    --     "integrationtest": {
    --       "521b0486-ab91-4d3a-9189-43c9380a0533": {
    --         "id": "521b0486-ab91-4d3a-9189-43c9380a0533",
    --         "name": "C1",
    --         "updatedAt": "2019-08-29T11:40:39.000Z"
    --       },
    --       "a236b715-e682-460b-97b6-c1db24f7612e": {
    --         "id": "a236b715-e682-460b-97b6-c1db24f7612e",
    --         "name": "C test",
    --         "updatedAt": "2019-08-29T10:18:11.000Z"
    --       }
    --     },
    --     "mock": {
    --       "4ccd755f-2c80-481b-a262-49b55e12f5e1": {
    --         "id": "4ccd755f-2c80-481b-a262-49b55e12f5e1",
    --         "name": "Mock",
    --         "url": "https://4ccd755f-2c80-481b-a262-49b55e12f5e1.mock-beta.pstmn.io",
    --         "updatedAt": "2019-08-20T10:18:13.000Z"
    --       }
    --     }
    --   }
    -- }

    -- 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, 'relations.contracttest.2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2.id'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'relations.contracttest.2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2.name'
    DECLARE @UpdatedAt nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @UpdatedAt OUT, 'relations.contracttest.2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2.updatedAt'
    DECLARE @v_521b0486_ab91_4d3a_9189_43c9380a0533Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_521b0486_ab91_4d3a_9189_43c9380a0533Id OUT, 'relations.integrationtest.521b0486-ab91-4d3a-9189-43c9380a0533.id'
    DECLARE @v_521b0486_ab91_4d3a_9189_43c9380a0533Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_521b0486_ab91_4d3a_9189_43c9380a0533Name OUT, 'relations.integrationtest.521b0486-ab91-4d3a-9189-43c9380a0533.name'
    DECLARE @v_521b0486_ab91_4d3a_9189_43c9380a0533UpdatedAt nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_521b0486_ab91_4d3a_9189_43c9380a0533UpdatedAt OUT, 'relations.integrationtest.521b0486-ab91-4d3a-9189-43c9380a0533.updatedAt'
    DECLARE @A236b715_e682_460b_97b6_c1db24f7612eId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @A236b715_e682_460b_97b6_c1db24f7612eId OUT, 'relations.integrationtest.a236b715-e682-460b-97b6-c1db24f7612e.id'
    DECLARE @A236b715_e682_460b_97b6_c1db24f7612eName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @A236b715_e682_460b_97b6_c1db24f7612eName OUT, 'relations.integrationtest.a236b715-e682-460b-97b6-c1db24f7612e.name'
    DECLARE @A236b715_e682_460b_97b6_c1db24f7612eUpdatedAt nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @A236b715_e682_460b_97b6_c1db24f7612eUpdatedAt OUT, 'relations.integrationtest.a236b715-e682-460b-97b6-c1db24f7612e.updatedAt'
    DECLARE @v_4ccd755f_2c80_481b_a262_49b55e12f5e1Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_4ccd755f_2c80_481b_a262_49b55e12f5e1Id OUT, 'relations.mock.4ccd755f-2c80-481b-a262-49b55e12f5e1.id'
    DECLARE @v_4ccd755f_2c80_481b_a262_49b55e12f5e1Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_4ccd755f_2c80_481b_a262_49b55e12f5e1Name OUT, 'relations.mock.4ccd755f-2c80-481b-a262-49b55e12f5e1.name'
    DECLARE @v_Url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Url OUT, 'relations.mock.4ccd755f-2c80-481b-a262-49b55e12f5e1.url'
    DECLARE @v_4ccd755f_2c80_481b_a262_49b55e12f5e1UpdatedAt nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_4ccd755f_2c80_481b_a262_49b55e12f5e1UpdatedAt OUT, 'relations.mock.4ccd755f-2c80-481b-a262-49b55e12f5e1.updatedAt'

    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}}/relations

Postman Collection Item JSON

{
  "name": "Get linked relations",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/relations",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "apis",
        "{{apiId}}",
        "versions",
        "{{apiVersionId}}",
        "relations"
      ]
    },
    "description": "This call fetches all the relations which are linked to the specified API version along with their details.\n\nThe response will contain a `relations` object which lists all the relation types which are linked to the API version. Each of the relation type will be an object which details the relations of this type. \n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
    {
      "name": "Get linked relations for an API version",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/relations",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "apis",
            "{{apiId}}",
            "versions",
            "{{apiVersionId}}",
            "relations"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "description": {
            "content": "",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
      ],
      "body": "{\n\t\"relations\": {\n\t\t\"contracttest\": {\n            \"2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2\": {\n                \"id\": \"2a9b8fa8-88b7-4b86-8372-8e3f6f6e07f2\",\n                \"name\": \"C test\",\n                \"updatedAt\": \"2019-08-29T10:18:11.000Z\"\n            }\n        },\n        \"integrationtest\": {\n            \"521b0486-ab91-4d3a-9189-43c9380a0533\": {\n                \"id\": \"521b0486-ab91-4d3a-9189-43c9380a0533\",\n                \"name\": \"C1\",\n                \"updatedAt\": \"2019-08-29T11:40:39.000Z\"\n            },\n            \"a236b715-e682-460b-97b6-c1db24f7612e\": {\n                \"id\": \"a236b715-e682-460b-97b6-c1db24f7612e\",\n                \"name\": \"C test\",\n                \"updatedAt\": \"2019-08-29T10:18:11.000Z\"\n            }\n        },\n        \"mock\": {\n            \"4ccd755f-2c80-481b-a262-49b55e12f5e1\": {\n                \"id\": \"4ccd755f-2c80-481b-a262-49b55e12f5e1\",\n                \"name\": \"Mock\",\n                \"url\": \"https://4ccd755f-2c80-481b-a262-49b55e12f5e1.mock-beta.pstmn.io\",\n                \"updatedAt\": \"2019-08-20T10:18:13.000Z\"\n            }\n        }\n\t}\n}"
    }
  ]
}