{"info":{"_postman_id":"ae001cb7-c0de-4472-89a6-176dd58c531e","name":"How to Update Schema using Postman API?","description":"<html><head></head><body><p>In order to update your API Schema - run the requests one after the other and saving the required value in a dedicated environment.</p>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[],"owner":"6034746","collectionId":"ae001cb7-c0de-4472-89a6-176dd58c531e","publishedId":"SzYUZLy5","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"EF5B25"},"publishDate":"2020-03-26T11:13:40.000Z"},"item":[{"name":"Fetch the Workspace-Id","id":"9194681a-9cdd-4f79-862d-858ca6ea92d9","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"x-api-key","value":"{{api-key}}","type":"text"}],"url":"https://api.getpostman.com/workspaces","description":"<p>This will fetch all the workspaces you are currently part of. Select the workspace-ID where your API is saved and update the respective environment.</p>\n","urlObject":{"protocol":"https","path":["workspaces"],"host":["api","getpostman","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"9194681a-9cdd-4f79-862d-858ca6ea92d9"},{"name":"Fetch the API","id":"7b2c1357-8919-4e3c-bef5-66e3b94a45bb","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"x-api-key","value":"{{key}}","type":"text"}],"url":"https://api.getpostman.com/apis?workspace={{workspaceId}}","description":"<p>Lists all the APIs within the selected Workspace. Select the API-Id for which you want to make the changes and update the environment.</p>\n","urlObject":{"path":["apis"],"host":["https://api.getpostman.com"],"query":[{"key":"workspace","value":"{{workspaceId}}"}],"variable":[]}},"response":[],"_postman_id":"7b2c1357-8919-4e3c-bef5-66e3b94a45bb"},{"name":"Fetch version of the API","id":"9382ee61-84d1-4d45-b615-ce3f66a8ac91","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"x-api-key","value":"{{key}}","type":"text"}],"url":"https://api.getpostman.com/apis/{{apiId}}/versions","description":"<p>Lists down the various versions of your API. Select the version of your API to which you want to make the changes and update the environment.</p>\n","urlObject":{"path":["apis","{{apiId}}","versions"],"host":["https://api.getpostman.com"],"query":[],"variable":[]}},"response":[],"_postman_id":"9382ee61-84d1-4d45-b615-ce3f66a8ac91"},{"name":"Fetch Schema ID","id":"fdaaad6d-8829-4dff-a2a4-882b895b802a","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"x-api-key","value":"{{key}}","type":"text"}],"url":"https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}","description":"<p>Lists down Id of your Schema. Make the changes and update the environment with the value.</p>\n","urlObject":{"path":["apis","{{apiId}}","versions","{{apiVersionId}}"],"host":["https://api.getpostman.com"],"query":[],"variable":[]}},"response":[],"_postman_id":"fdaaad6d-8829-4dff-a2a4-882b895b802a"},{"name":"Update Schema","event":[{"listen":"prerequest","script":{"id":"8ff07b78-7886-497f-b47f-1a3f74afd383","exec":["const schema = JSON.stringify({","\t\"info\": {","\t\t\"_postman_id\": \"5dc7f8b1-3ab2-4cc9-8a73-0d09e774c6b0\",","\t\t\"name\": \"Postman Support\",","\t\t\"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\"","\t},","\t\"item\": [","\t\t{","\t\t\t\"name\": \"Postman Update API Schema - Generic Services fame\",","\t\t\t\"request\": {","\t\t\t\t\"auth\": {","\t\t\t\t\t\"type\": \"apikey\",","\t\t\t\t\t\"apikey\": [","\t\t\t\t\t\t{","\t\t\t\t\t\t\t\"key\": \"value\",","\t\t\t\t\t\t\t\"value\": \"{{vault:postman-api-key}}\",","\t\t\t\t\t\t\t\"type\": \"string\"","\t\t\t\t\t\t},","\t\t\t\t\t\t{","\t\t\t\t\t\t\t\"key\": \"key\",","\t\t\t\t\t\t\t\"value\": \"x-api-key\",","\t\t\t\t\t\t\t\"type\": \"string\"","\t\t\t\t\t\t}","\t\t\t\t\t]","\t\t\t\t},","\t\t\t\t\"method\": \"PUT\",","\t\t\t\t\"header\": [","\t\t\t\t\t{","\t\t\t\t\t\t\"key\": \"\",","\t\t\t\t\t\t\"value\": \"\",","\t\t\t\t\t\t\"type\": \"text\",","\t\t\t\t\t\t\"disabled\": true","\t\t\t\t\t}","\t\t\t\t],","\t\t\t\t\"body\": {","\t\t\t\t\t\"mode\": \"raw\",","\t\t\t\t\t\"raw\": \"{\\n\\t\\\"language\\\": \\\"yaml\\\",\\n\\t\\\"schema\\\": \\\"openapi: 3.0.0\\\\ninfo:\\\\n  description: Parloa Global Services\\\\n  version: \\\\\\\"1.0.3\\\\\\\"\\\\n  title: Parloa Global Services\\\\n\\\",\\n\\t\\\"type\\\": \\\"openapi3\\\"\\n }\",","\t\t\t\t\t\"options\": {","\t\t\t\t\t\t\"raw\": {","\t\t\t\t\t\t\t\"language\": \"json\"","\t\t\t\t\t\t}","\t\t\t\t\t}","\t\t\t\t},","\t\t\t\t\"url\": {","\t\t\t\t\t\"raw\": \"https://api.getpostman.com/apis/d055de50-0d6f-4d02-8354-1d8a127b46dc/versions/741be61d-840b-406d-842a-fb708b8b3424/schemas/25ad1f6d-b1b4-4ad9-a06c-8e3d0f4e65d3\",","\t\t\t\t\t\"protocol\": \"https\",","\t\t\t\t\t\"host\": [","\t\t\t\t\t\t\"api\",","\t\t\t\t\t\t\"getpostman\",","\t\t\t\t\t\t\"com\"","\t\t\t\t\t],","\t\t\t\t\t\"path\": [","\t\t\t\t\t\t\"apis\",","\t\t\t\t\t\t\"d055de50-0d6f-4d02-8354-1d8a127b46dc\",","\t\t\t\t\t\t\"versions\",","\t\t\t\t\t\t\"741be61d-840b-406d-842a-fb708b8b3424\",","\t\t\t\t\t\t\"schemas\",","\t\t\t\t\t\t\"25ad1f6d-b1b4-4ad9-a06c-8e3d0f4e65d3\"","\t\t\t\t\t]","\t\t\t\t}","\t\t\t},","\t\t\t\"response\": []","\t\t}","\t],","\t\"protocolProfileBehavior\": {}","});","pm.environment.set('schema', JSON.stringify(schema));"],"type":"text/javascript"}}],"id":"1f77c1ad-051a-482c-858b-e28d1a0ba911","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"PUT","header":[{"key":"x-api-key","value":"{{key}}","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"}],"body":{"mode":"raw","raw":"{\n\t\"schema\": {\n\t\t\"language\": \"yaml\",\n\t\t\"type\": \"openapi3\",\n\t\t\"schema\": {{schema}}\n\t}\n}","options":{"raw":{"language":"json"}}},"url":"https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}/schemas/{{schemaId}}","description":"<p>Update your schema using the Pre-request scripts which will update the environment and will update the same.</p>\n","urlObject":{"path":["apis","{{apiId}}","versions","{{apiVersionId}}","schemas","{{schemaId}}"],"host":["https://api.getpostman.com"],"query":[],"variable":[]}},"response":[],"_postman_id":"1f77c1ad-051a-482c-858b-e28d1a0ba911"}],"event":[{"listen":"prerequest","script":{"id":"bc2c77ec-8ed3-4d11-bc71-83be3f46d8be","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"fa41d8d8-49b2-4f35-94d4-5a5ba6b2e573","type":"text/javascript","exec":[""]}}],"variable":[{"key":"url","value":"https://api.getpostman.com"}]}