How to update variables while running a collection in a monitor

I have the following setup:

  1. Get request which pulls data into three variables (currencies)
  2. Post Request which gives me a new acces token and refresh token and puts it into two variables.
  3. Post request which uses all the variables to update an XML ‘template’ (in body as code) and push it to the service.

All this is setup in a collection. This all works fine when running this through postman itself. However, I need to ‘schedule’ this to run everyday at a certain time. I thought of using a monitor, but this doesn’t work. It works the very first time I run it, but after this it doesn’t. It doesn’t update the variables anymore, and uses ‘old’ data, such as the old refresh token, resulting in a 401 unauthorized.

I may be doing something wrong here. The variables are not global but put in a specific environment.

Is monitoring the way to do this? Or can I use a different way to schedule this daily? I have a server available where I could set this up to do so but it would be nicer to run this cloud based.

@v.verhulst The test scripts won’t update the environment while running them in a monitor.
You’ll need to use the Postman API to get this working.

Edit: You can import the Postman API from here:
into your app and read the docs to add the request to update the environment.

Docs for updating the environment using the Postman API:

You can either make use of pm.sendRequest in a test script of the request where you’re updating the environment.

Or you can place the update environment requests separately as standalone requests, so when the collection is running in the monitor, this request would update the environment.


Thanks, this explains why.

Can I use the newman console way to do this without fully overhauling my current requests? Since the knowledge is limited.

When I run the collection it gives the same result. Variables aren’t updated either. Does this work in the same way as the monitor?

@v.verhulst, you can use newman to do it via the terminal or you can use the collection runner in the postman app itself.
Both should work properly and the scripts will update the environment as you expect them to be updated.

For newman: If you want to for say, export this updated environment later after the collection has been finished running, you can read the 2nd point in this answer.

Also to add, monitor is useful when you want to schedule a collection run for let’s say, run a monitor every day at a certain time or weekly, or so.
Monitor has different use-cases which might be interesting to you, you can read more about it here.

After some tinkering I’m able to run my collection, multiple times in a row. So this works.

The next step is to run it through the console. However, this gives an issue.

I use the command:

newman run FOREXCOLL.json -e FOREXENV.json

The first request works (loading data), the second one (updating the tokens) does not. This gives me an error:

│ ‘{“error”:“invalid_request”}’

The last step is no longer being executed.

Any clue why it does this? Am I missing any more details?

Screenshot below:

I also tried changing the order of the different requests but this doesn’t make any difference.
I’m NOT using the AUTH helper in Postman since for this usecase it didn’t work. I am refreshing a token in this script which gives me a new acces token usable to do the actual push of data.

@v.verhulst Yes, this is currently a known issue in Node 12.
Here’s the issue that has been raised around it:

I request you to follow the thread on GitHub for any updates around it.

As a workaround, you can either downgrade your node version to 10.15.3 or use a node package manager such as n or nvm to manage multiple node versions on your machine and run newman using a lower node version.