1

I am trying to set a request after a certain request in postman, but It is not working as I want it to be. I have read through Postman documentation but got no luck. Plus, how do I get postman's request ID?

I am using the given JavaScript in the Test tab, and in postman documentation it says it should work. But no luck.

postman.setNextRequest('Login');

Arslan Ahmed
  • 52
  • 1
  • 6
  • It would be helpful if you can share your collection. And also can you explain what is the exact problem you are facing? like what is the outcome you are expecting and what is the outcome you are getting ? – Avishek Saha Aug 23 '19 at 09:33
  • Duplicate of https://stackoverflow.com/questions/57609395/postman-setnextrequest-unable-to-pass-request-id – Danny Dainton Aug 23 '19 at 09:35
  • @AvishekSaha Please refer to this screenshot: https://www.screencast.com/t/jwZK9z1K – Arslan Ahmed Aug 23 '19 at 09:36
  • Can you make sure that `postman.setNextRequest('Login');` is inside a test script of a request which is inside the same collection where the `login` request resides? – Avishek Saha Aug 23 '19 at 09:39
  • Yes it is inside the same collection. – Arslan Ahmed Aug 23 '19 at 13:12
  • `setNextRequest()` only works inside the Runner. It will be ignored if you just press the `Send` button and dispatch your request. Please, make sure that this is not the issue here. @ArslanAhmed – Oleg Jun 22 '20 at 20:32

1 Answers1

3

postman.setNextRequest('Login') will work only inside the Runner. Also, the requests need to be in the same Collection.

Even if the request is in another folder (while still in the same collection), you can reference it in setNextRequest(), without having to specify any folder.

And to answer your second question, "how to get the Postman Request Id?" Use this pm.info.requestId which will return string value, you may set that in environment variable as well, like pm.environment.set("rID", pm.info.requestId)

Oleg
  • 654
  • 1
  • 7
  • 16
  • In the new UI, you can also find it the ID by clicking on the request you want the ID for, the, go to the (i) button in the far right sidebar (where you usually grab the curl, e.g.). The code way is probably safer against maintenance-introduced issues, though. – Kreidol May 28 '21 at 22:31
  • I can get it just fine in the UI as stated above, but how do you USE it? Passing the GUID in `setNextRequest("GUIDhere")` does not succeed. This would enrich this answer, as it can't be found elsewhere. Thanks! – Kreidol Jun 28 '21 at 19:06
  • What if you have a request with the same name in the same collection? It happens a lot in our collection. The Postman documentation is silent about this... – Frans Jul 12 '21 at 12:49
  • @Kreidol, if you're taking the request ID from the Postman UI (the "i" button), then note that that id also contains the user id as a prefix, a mentioned in the docs here: "Note that the ID shown is the user ID followed by the request ID. **Omit** the first eight digits and dash to get the request ID" – userfuser Mar 29 '22 at 10:42
  • Circling back to this, as I figured it out ages ago and lost the thread. You pass it by removing the first section of GUID characters and sending it as a string. Given `12345678-2222483b-0555-4c49-a97f-65836bf3d811`, send `pm.setNextRequest("2222483b-0555-4c49-a97f-65836bf3d811");` – Kreidol Jun 23 '22 at 01:58