Postman: Access environment variables or read from file

Viewed 810

I'm trying to test an API that needs AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN). Right now I'm setting them explicitly in the Postman environment, but I need to do this every time I'm refreshing my credentials. So I'm looking for a way to automatically add these and found Postman pre-request scripts.

Unfortunately there is no process.env and also no fs.readFileSync(to read ~/.aws/credentials). Is there another way to pass information from outside Postman?

1 Answers

You could pass those values in with Newman:

The --env-var flag can be using the resolve placeholder variables in a collection {{token}} to the value passed at runtime.

When using Newman from the Command Line

newman run collection.json --env-var "token=$TOKEN"

When using Newman as a library:

const newman = require('newman')

newman.run({
  collection: 'collection.json',
  envVar: [ 
      { "key":"token", "value":`${process.env.TOKEN}`}
  ],
})
Related