Is it possible to do different requests (GET and then POST) within one request?

I am sending 4 requests in the following order:
GET Request - which gives me ID
POST Request - which I need the ID from the GET request
GET Request - -which gives me an actionID
POST Request - which I need the actionID from the GET Request.

What is the best way to set this up using collection variables and some looping?

Hi Ameen, you could use a collection runner but a better way to do this is with Postman Flows. If you haven’t used it before, you can turn it on in your workspace settings and give it a try (docs Build API-first apps with Postman Flows—a visual, low-code editor | Postman Learning Center).

I don’t have access to Postman Flows. Any ideas how to do this leveraging the pre-request scripts and post -request scripts.

Thanks.

Hi @ameenjafferie,

Another approach you can try is the pm.sendRequest with your Pre and Test script areas.

I use this approach to try to reduce the number of steps in a test, which are essentially test setup steps.

There is also an example in another post in the community here

Also if you need the requests to run in a certain order, I’d recommend using async/await (promises) to guarantee they are sent in the correct order. Examples here

I’d consider using the package library to avoid lots of duplicated code., if this is something you will be doing regularly,

2 Likes

Check this flow: I fetch the ID using a GET request and then push it using a POST request.

Flows Link
https://www.postman.com/solar-shadow-357008/incident-io-api/flow/675a129d34be910031e63111

I’m not seeing the need for anything special here, or to use sendRequest() and the associated issues with awaits.

I can’t see where you need a loop. It just looks like you need to run the requests in order using the collection runner with the post response script at each stage parsing the response to retrieve the relevant key/value to be save as a collection\environment variable for the subsequent request. (Pretty standard stuff which is covered in the Postman Learning Centre training).

If it does need to loop. On which request does it need to loop? One of the request, or all 4 requests? We need a bit more information to advise on the best solution.

Do you really mean to run all of this within one request (in which case you are limited to using sendRequest() and the associated challenges with async requests). The only reason I can see for this would be to potentially get around the collection runner limits.

To answer the question. Is it possible to run this as a single request? The answer is no. As sendRequest() is still sending a request. If the question is can I run the 4 requests as a single request in the GUI, then the answer is “yes” using sendRequest() and the other 3 requests either as pre-request scripts, or post-response scripts, but do you really need to do this with all of the extra complications as using the collection runner would be the normal method for this.

1 Like