Update postman collection programatically

Viewed 673

My application generates Open API/Swagger specification file. It may have new API additions/updates. I want to have an automated script/job which uploads/updates this specification into existing postman collection. I looked in Powershell, Terraform, Postman APIs but they don't support it.

Is there any other way to achieve what I want ?

1 Answers

The postman has an official tool called swagger2-postman2-converter to update postman.

And the official blog Sync your specs describes in detail how to update collections using this tool.

Here are the detailed steps. I am using the sample code provided by postman. You can replace your file with the corresponding file in the sample.

  1. If you don't have a Postman API key, go to your account settings and generate one. Click Postman API for detailed information.

  2. Stored your key in a json file. The _secrets.json file in this sample.

  3. Run the GET API to get your collection_uid and collection_id and update the config.js file.

Get All Collections: https://api.getpostman.com/collections

Get Single Collection: https://api.getpostman.com/collections/{{collection_uid}}

  1. Run npm install fs swagger2-postman2-converter to install the dependencies.

  2. Run node converter.js

  3. Run PUT API to update your collection.

PUT Update Collection: https://api.getpostman.com/collections/{{collection_uid}}

After you have run it once, if you have any updates to your swagger.json file, you only need to perform steps 5 and 6.

Related