Can you log the value of Y in the token generation request in the console and see if it indeed returns a value? Ideally, if all looks good, AuthToken should be the value of Y n your last request.
Alternatively, if you could use a different variable name to store Y to test and see if that works as against updating the value of AuthToken.
I did a bit of console.logs.
So I added a code similar to the folowing to all the folders and requests Pre-request and Post-response. console.log("[Demo-X-Y].[Scripts].[Pre-response]" + pm.environment.get("AuthToken"));
It appeasrs to befor every request all the porst requests are getting executed along the hierarchy from top to bottom. So the only instance that value “Y” is assigned to the variable is at the Post-response of the Token generation request.
Hi @asanke. I am not sure I understand the question here correctly.
Pre-request script runs before a request is run and post-response script run after a response is gotten. What order are you trying to re-order or limit?
So as I observe, before every request, postman runs all the pre request scripts along the hierarchy. ( Check the screenshot in my previous response). That would reset the value to X before each request.
The order I observed is …
[Demo-X-Y].[Screipts].[Pre-response] → Vallue is “X”
[Group Folder].[Screipts].[Pre-response]
[Sub Folder].[Screipts].[Pre-response]
[request-1].[Screipts].[Pre-response] → Value unset
[Demo-X-Y].[Screipts].[Post-response]
[Group Folder].[Screipts].[Post-response]
[Sub Folder].[Screipts].[Post-response]
[request-1].[Screipts].[Post-response]
[Demo-X-Y].[Screipts].[Pre-response] → Vallue is set back to “X”
Any script authored at the folder or at the collection level will run against every request in that folder or collection. I think this could be the reason why the value keeps updating on every iteration.
If your intention is not to run the pre-request script against every single request, then I will recommend that you do not author them at the collection or folder level.