Execute other Request By Id in the Pre-request Script

Hey coming here from Insomnia but guess this is the product that my company has…
Can you please tell my why it doesn’t seem to be able to execute another request by ID
in the Pre-request Script section ?
i want to build a simple flow of 3 request
create-session(exract_session_id) → authenticate(extract_token) → do_actuall_call(using the token)

can i really only do this with collection runners ? (<- horrible)

And if it has to be those collection runners… why can’t i save them for my team to use?

Hey! Welcome to the Postman community!

I think what you’re looking for would be found here.
With setNextRequest you can use request name or request ID.

Hope this helps :smile:

Hey Kevin thanks for the response. Set nextrequest does not work for me in a pre-request script. Tried to set the request itself to the env but that does not work since the test part of a request is not executed

And if I understand correctly it want the opposite of that. Otherwise you cannot build dependencies and reuse requests

SetNextRequest would create

A → B → C

There decided what to run before can build

A ← B ← C
… ^- D
… …^- E

Hi there - if you would like an example of send next request and working with this workflow, take a look at my collection - Visualizing Postmanauts across the globe.
In the third folder - Using Request workflows, you can see how postman.setNextRequest() method is utilized.


you don’t really seem to understand what send next request is not what i want. i want doBeforeRequest executed with pre-script and test.
when doing only next request you can only build forward dependencies which is stupid if you want to reuse request chains.

maybe this explains it better…
Request A: create session, store session id in ENV
Request B: get Auth token, uses session id from ENV, creates token which is stored in ENV

Request C: does something with that token (A and B have to be run before, always)

yes you could do that with A.setNext(B) B.setNext(C) BUT
image there is a Request D - Z
all of them need A and B before
with the forward dependency you need to replicate A and B for all cases D - Z since it can only beforward.

Insomnia does this very well. maybe try your competitor and learn.
I’ve seen that you also have a FLOW feature that might be able todo what i want by chaining request as i need it… yet the client gives me error and has the + (create) button disabled

Hi again,

Your initial question was about executing other requests by their ID in the pre-request script, which is possible. What you are looking to achieve is possible with setNextRequest. It may be different from the way you are used to and may require some creative thinking, but there are also collection level and folder level pre-request / test sections that could help you accomplish this too.

In your example of sessions and auth, if A and B are always going to be required for other requests, you can make that a pre-request script instead of two separate requests.

For example, If all of the requests in a collection will need to rely on A & B, move the A & B logic to the collection level pre-request script to store your IDs in the environment. Then anytime you run a request, it’s going to do something with that token. If it’s not all requests in a collection, you can put the ones that do need it into a folder under a collection and give that folder the pre-request script.

Much of this and more is explained in our docs page on writing pre-request scripts.
If you need some reference, I built a Slack bot that authenticates with the Twitch API in this way by using a collection level pre-request script before every request.

As for Flows, you can learn more about them here.