I have the following setup:
- Get request which pulls data into three variables (currencies)
- Post Request which gives me a new acces token and refresh token and puts it into two variables.
- 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: https://explore.postman.com/api/1590
into your app and read the docs to add the request to update the environment.
Docs for updating the environment using the Postman API: https://docs.api.getpostman.com/?version=latest#6517e0d6-3bc3-3da5-ab57-7a578a8504ce
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.
2 Likes
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ā}ā
_tls_wrap.js:547
self._destroySSL();
^
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: https://github.com/postmanlabs/newman/issues/2015
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.