damnatus
damnatus

Reputation: 23

How to chain these two Postman requests

I'm new to Postman and I am trying to automate usage of these two requests. The first one is a POST request which returns a JSON with a single key:value pair ("id") in it The second one is a POST request which just returns 200 OK

So far I've managed to save "id" from the 1st request's response to an environment variable.

However, I still need to do the following: After sending 1st request, wait about 30 seconds, put "id" from first request in the URL of 2nd request, then send 2nd request.

Upvotes: 1

Views: 1609

Answers (2)

PDHide
PDHide

Reputation: 19929

To wait 30 sec use setTImeout in prerequest script:

setTimeout(()=>{},30000)

This will wait for 30 seconds

Now to send the id url you can directly add it to url as {{id}} or in prerequest script add :

pm.request.addQueryParams({key:"id",value:pm.variables.get("id")})

if you want to run the request again and again till you get 200:

add this to test section of request 2

if (pm.response.code !== 200) {
    setTimeout(()=>{postman.setNextRequest(pm.info.requestName)},5000)
    

}

Note: there is a automatic delay between request option in postman you can use that also.

Also setNextRequest works only if you run using newman or colection runner

Upvotes: 1

Tnadev
Tnadev

Reputation: 10072

In the below image, you can find a delay option before you try to run postman. This option is used to add a delay between requests running in the runner.

You can check my video to learn more about postman runner and request chaining. Postman Runner and Request Chaining Explained in Detail enter image description here

Upvotes: 0

Related Questions