SQL Server / Postman API / Update 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
DECLARE @iTmp0 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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "workspace": {
-- "name": "New Workspace updated",
-- "description": "Some description",
-- "collections": [
-- {
-- "id": "e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d",
-- "name": "Straw hats",
-- "uid": "8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d"
-- }
-- ],
-- "environments": [
-- {
-- "id": "83a1aaa2-a204-4bd8-9b92-4d486918906b",
-- "name": "env",
-- "uid": "8154-83a1aaa2-a204-4bd8-9b92-4d486918906b"
-- }
-- ],
-- "mocks": [
-- {
-- "id": "cda672ef-1375-40e9-baee-e20ece8d7b65"
-- }
-- ],
-- "monitors": [
-- {
-- "id": "1e889bd2-3862-4be0-b2c2-9b1fe9673aec"
-- }
-- ]
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.name', 'New Workspace updated'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.description', 'Some description'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.collections[0].id', 'e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.collections[0].name', 'Straw hats'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.collections[0].uid', '8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.environments[0].id', '83a1aaa2-a204-4bd8-9b92-4d486918906b'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.environments[0].name', 'env'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.environments[0].uid', '8154-83a1aaa2-a204-4bd8-9b92-4d486918906b'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.mocks[0].id', 'cda672ef-1375-40e9-baee-e20ece8d7b65'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'workspace.monitors[0].id', '1e889bd2-3862-4be0-b2c2-9b1fe9673aec'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-API-Key', '{{postman_api_key}}'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://api.getpostman.com/workspaces/{{workspace_id}}', @sbRequestBody, 'utf-8', 'application/json', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
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 @resp, 'GetBodySb', @success OUT, @sbResponseBody
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 @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "workspace": {
-- "id": "cfbcd9bf-cc8b-4d6f-b8ef-440a3e49e29f",
-- "name": "New Workspace"
-- }
-- }
-- 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, 'workspace.id'
DECLARE @Name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'workspace.name'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X PUT
-H "X-API-Key: {{postman_api_key}}"
-H "Content-Type: application/json"
-d '{
"workspace": {
"name": "New Workspace updated",
"description": "Some description",
"collections": [
{
"id": "e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d",
"name": "Straw hats",
"uid": "8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d"
}
],
"environments": [
{
"id": "83a1aaa2-a204-4bd8-9b92-4d486918906b",
"name": "env",
"uid": "8154-83a1aaa2-a204-4bd8-9b92-4d486918906b"
}
],
"mocks": [
{
"id": "cda672ef-1375-40e9-baee-e20ece8d7b65"
}
],
"monitors": [
{
"id": "1e889bd2-3862-4be0-b2c2-9b1fe9673aec"
}
]
}
}'
https://api.getpostman.com/workspaces/{{workspace_id}}
Postman Collection Item JSON
{
"name": "Update Workspace",
"request": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"workspace\": {\n \"name\": \"New Workspace updated\",\n \"description\": \"Some description\",\n \"collections\": [\n {\n \"id\": \"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\",\n \"name\": \"Straw hats\",\n \"uid\": \"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\"\n }\n ],\n \"environments\": [\n {\n \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",\n \"name\": \"env\",\n \"uid\": \"8154-83a1aaa2-a204-4bd8-9b92-4d486918906b\"\n }\n ],\n \"mocks\": [\n {\n \"id\": \"cda672ef-1375-40e9-baee-e20ece8d7b65\"\n }\n ],\n \"monitors\": [\n {\n \"id\": \"1e889bd2-3862-4be0-b2c2-9b1fe9673aec\"\n }\n ]\n }\n}"
},
"url": {
"raw": "https://api.getpostman.com/workspaces/{{workspace_id}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"workspaces",
"{{workspace_id}}"
]
},
"description": "This endpoint allows you to update a workspace and update it's association to entities like `collections`, `environments`, `mocks` and `monitors` using their `uid`.\n\nOn successful updation of the workspace, the response returns the workspcae `name` and `id`.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter.\n\n**Note** : The endpoint expects you to send the desired state of the workspace in terms of the associated entities so be careful when trying to update these entities.\n\nFor eg. if your workspace has collections A and B, and in the update call, you send C's uid in the collections array, then A and B would be removed from the workspace and C would be added."
},
"response": [
{
"name": "Specified workspace/entities do not exist",
"originalRequest": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"workspace\": {\n \"name\": \"New Workspace updated\",\n \"description\": \"Some description\",\n \"collections\": [\n {\n \"id\": \"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\",\n \"name\": \"Straw hats\",\n \"uid\": \"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\"\n }\n ],\n \"environments\": [\n {\n \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",\n \"name\": \"env\",\n \"uid\": \"8153-83a1aaa2-a204-4bd8-9b92-4d486918906b\"\n }\n ],\n \"mocks\": [\n {\n \"id\": \"cda672ef-1375-40e9-baee-e20ece8d7b65\"\n }\n ],\n \"monitors\": [\n {\n \"id\": \"1e889bd2-3862-4be0-b2c2-9b1fe9673aec\"\n }\n ]\n }\n}"
},
"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"
}
],
"cookie": [
],
"body": "{\n \"error\": {\n \"name\": \"instanceNotFoundError\",\n \"message\": \"The specified workspace does not exist.\"\n }\n}"
},
{
"name": "Successful Response",
"originalRequest": {
"method": "POST",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"workspace\": {\n \"name\": \"New Workspace\",\n \"description\": \"Some description\",\n \"collections\": [\n {\n \"id\": \"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\",\n \"name\": \"Straw hats\",\n \"uid\": \"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\"\n }\n ],\n \"environments\": [\n {\n \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",\n \"name\": \"env\",\n \"uid\": \"8154-83a1aaa2-a204-4bd8-9b92-4d486918906b\"\n }\n ],\n \"mocks\": [\n {\n \"id\": \"cda672ef-1375-40e9-baee-e20ece8d7b65\"\n }\n ],\n \"monitors\": [\n {\n \"id\": \"1e889bd2-3862-4be0-b2c2-9b1fe9673aec\"\n }\n ]\n }\n}"
},
"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\": \"cfbcd9bf-cc8b-4d6f-b8ef-440a3e49e29f\",\n \"name\": \"New Workspace\"\n }\n}"
},
{
"name": "Not enough permissions",
"originalRequest": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"workspace\": {\n \"name\": \"New Workspace updated\",\n \"type\": \"personal\",\n \"description\": \"Some description\",\n \"collections\": [\n {\n \"id\": \"e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\",\n \"name\": \"Straw hats\",\n \"uid\": \"8154-e1fc3c38-a0b8-44a3-bd44-d753a96b2e9d\"\n }\n ],\n \"environments\": [\n {\n \"id\": \"83a1aaa2-a204-4bd8-9b92-4d486918906b\",\n \"name\": \"env\",\n \"uid\": \"8154-83a1aaa2-a204-4bd8-9b92-4d486918906b\"\n }\n ],\n \"mocks\": [\n {\n \"id\": \"cda672ef-1375-40e9-baee-e20ece8d7b65\"\n }\n ],\n \"monitors\": [\n {\n \"id\": \"1e889bd2-3862-4be0-b2c2-9b1fe9673aec\"\n }\n ]\n }\n}"
},
"url": {
"raw": "https://api.getpostman.com/workspaces/{{workspace_id}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"workspaces",
"{{workspace_id}}"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n \"error\": {\n \"name\": \"forbiddenError\",\n \"message\": \"You do not have access to update this workspace.\"\n }\n}"
}
]
}