Collection download via API call

I’m hoping to use Newman in a Jenkins pipeline to run a Collection.

To that end I want to download the collection from Postman to a local filesystem on my CICD server.

I have read the article at https://www.getpostman.com/docs/postman/collection_runs/integration_with_jenkins but it looks like the collection files are already in place which isn’t going automatically pickup changes in my Team Collections.

So to reiterate how do I programatically download a collection. Is there an API for this. In fact is there an API for managing Collections in general.

BTW we are using Postman Pro.

1 Like

Hi @TimArmstrong,

  1. You can use the Postman API to download the collection JSON https://docs.api.getpostman.com/#647806d5-492a-eded-1df6-6529b5dc685c. This returns the latest data which is synced.
  2. Save the response in a file <filename>
  3. Finally, you can run the latest collection using newman run <filename>

Hope, this helps.

1 Like

Hello Ankit,

Ok that worked a treat.

Will update my question when I get everything working.

Tim

1 Like

@ankit-mI don’t think there is a need to save the response as a file. You should be able to directly call the API using newman run .

1 Like

Hello Abhinav,

So I tried a few things but couldn’t get things to work as a one line command.

Last failed attempt was

newman run https://api.getpostman.com/collections/

Tim

@TimArmstrong You can follow the link to call Postman Pro APIs to fetch the collections and environments (If required for Newman run) at the time of Newman run. (No need to store them in any file)

Few points:-

  1. You are required to have a valid API key to fetch collection/environments
  2. The uid is the user_id-collection_id which you have to provide to fetch the specific collection for Newman run.

Hope this is what you are looking for.

Hello Prakhar,

So it’s working now.

newman run “https://api.getpostman.com/collections/9999999-3d5e3244-9408-efbb-7767-999999999999?apikey=99999999999999999999999999999999” -e DEV1_Environment.json

My problem was I had not wrapped my URL in double quotes and so I suspect the shell was helping me by further interpreting my command and make a mess of things.

Tim

1 Like