Chilkat Online Tools

SQL Server / Postman API / Single workspace

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/workspaces/{{workspace_id}}', @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)

    -- {
    --   "workspace": {
    --     "id": "f8801e9e-03a4-4c7b-b31e-5db5cd771696",
    --     "name": "Demo workspace",
    --     "type": "personal",
    --     "description": "Demos.",
    --     "collections": [
    --       {
    --         "id": "7c31b469-bd43-4411-9283-6d397855ee0e",
    --         "name": "Mock demo - collection",
    --         "uid": "1234-7c31b469-bd43-4411-9283-6d397855ee0e"
    --       },
    --       {
    --         "id": "356fe068-a0f8-4f31-b34d-d12149eac681",
    --         "name": "Mock demo - response code",
    --         "uid": "1234-356fe068-a0f8-4f31-b34d-d12149eac681"
    --       }
    --     ],
    --     "environments": [
    --       {
    --         "id": "423fd955-a9c8-47cd-9ab0-09a6a575c4be",
    --         "name": "Mock demo - CNX",
    --         "uid": "1234-423fd955-a9c8-47cd-9ab0-09a6a575c4be"
    --       },
    --       {
    --         "id": "24c45c84-5147-4c15-bb9a-c3186b81d3cc",
    --         "name": "Mock Demo - response code",
    --         "uid": "1234-24c45c84-5147-4c15-bb9a-c3186b81d3cc"
    --       }
    --     ],
    --     "mocks": [
    --       {
    --         "id": "77aaeba0-0f94-4aa4-a60d-200f4e1ef2fb"
    --       },
    --       {
    --         "id": "52a5d86f-73d4-4f86-baec-4b19983d6896"
    --       }
    --     ],
    --     "monitors": [
    --       {
    --         "id": "efa46ba3-90da-4a84-b924-2962266c3db1"
    --       },
    --       {
    --         "id": "24915c49-b33e-4da1-ac20-535f82e34626"
    --       }
    --     ]
    --   }
    -- }

    -- 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 @uid nvarchar(4000)

    DECLARE @Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'workspace.id'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'workspace.name'
    DECLARE @v_Type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'workspace.type'
    DECLARE @Description nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'workspace.description'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'workspace.collections'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'workspace.collections[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'workspace.collections[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @uid OUT, 'workspace.collections[i].uid'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'workspace.environments'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'workspace.environments[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'workspace.environments[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @uid OUT, 'workspace.environments[i].uid'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'workspace.mocks'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'workspace.mocks[i].id'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'workspace.monitors'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'workspace.monitors[i].id'
        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/workspaces/{{workspace_id}}

Postman Collection Item JSON

{
  "name": "Single workspace",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.getpostman.com/workspaces/{{workspace_id}}",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "workspaces",
        "{{workspace_id}}"
      ]
    },
    "description": "Access the contents of a workspace that is accessible to you using its id (`id`). Includes the collections, environments, mocks and monitors of that workspace.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
    {
      "name": "Workspace Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/workspaces/{{workspace_id}}",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "workspaces",
            "{{workspace_id}}"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "name": "Content-Type",
          "description": {
            "content": "The mime type of this content",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"error\": {\n        \"name\": \"instanceNotFoundError\",\n        \"message\": \"Instance not found in the database.\"\n    }\n}"
    },
    {
      "name": "Valid Response",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/workspaces/{{workspace_id}}",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "workspaces",
            "{{workspace_id}}"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "description": {
            "content": "",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"workspace\": {\n        \"id\": \"f8801e9e-03a4-4c7b-b31e-5db5cd771696\",\n        \"name\": \"Demo workspace\",\n        \"type\": \"personal\",\n        \"description\": \"Demos.\",\n        \"collections\": [\n            {\n                \"id\": \"7c31b469-bd43-4411-9283-6d397855ee0e\",\n                \"name\": \"Mock demo - collection\",\n                \"uid\": \"1234-7c31b469-bd43-4411-9283-6d397855ee0e\"\n            },\n            {\n                \"id\": \"356fe068-a0f8-4f31-b34d-d12149eac681\",\n                \"name\": \"Mock demo - response code\",\n                \"uid\": \"1234-356fe068-a0f8-4f31-b34d-d12149eac681\"\n            }\n        ],\n        \"environments\": [\n            {\n                \"id\": \"423fd955-a9c8-47cd-9ab0-09a6a575c4be\",\n                \"name\": \"Mock demo - CNX\",\n                \"uid\": \"1234-423fd955-a9c8-47cd-9ab0-09a6a575c4be\"\n            },\n            {\n                \"id\": \"24c45c84-5147-4c15-bb9a-c3186b81d3cc\",\n                \"name\": \"Mock Demo - response code\",\n                \"uid\": \"1234-24c45c84-5147-4c15-bb9a-c3186b81d3cc\"\n            }\n        ],\n        \"mocks\": [\n            { \n                \"id\": \"77aaeba0-0f94-4aa4-a60d-200f4e1ef2fb\"\n            },\n            { \n                \"id\": \"52a5d86f-73d4-4f86-baec-4b19983d6896\"\n            }\n        ],\n        \"monitors\": [\n            {\n                \"id\": \"efa46ba3-90da-4a84-b924-2962266c3db1\"\n            },\n            {\n                \"id\": \"24915c49-b33e-4da1-ac20-535f82e34626\"\n            }\n        ]\n    }\n}"
    }
  ]
}