Execute request in collection runner after successfully completing first request

I am trying to deploy cloud VM’s using Postman and below is the workflow that I am trying accomplish.

1.) Send request to deploy VM image. (it may take few minutes for the vm to be successfully deployed).
2.) Send another request to check the status of VM deployment , check response for completion.
3.) If response is not completed , send another health check request after 10 seconds, until response contains completed.
4.) If response for above health is successful , execute next request in collection.

Thanks

Hi @abdulwasay.1218!

You should be able to accomplish this using postman.setNextRequest() and setTimeout().

  1. Send request to deploy VM image
  2. Send request to check completion
  • In pre-request script of this request, include the following to delay 10 seconds if the deployment has been tested previously, and is not finished yet:
if(!pm.variables.has('timeoutCheck'))
{
    pm.variables.set('timeoutCheck', false);
}

var timeoutCheck = pm.variables.get('timeoutCheck');

if(timeoutCheck === true)
{
    setTimeout(function(){console.log('waiting...')},10000);
}
  • In Test script of this request, include something like the following to check for a success condition, and if not present loop the request again with a 10 second delay
var requestStatus = pm.variables.get('status');

// check for your success condition. Response code 200 is used as an example here.
if (pm.response.code != 200) {
    // indicate that a delay should be used when looping this request again
    pm.variables.set('timeoutCheck',true);
    // loop this request again
    postman.setNextRequest(pm.info.requestName);
    
} else if (pm.response.code === 200){
    // proceed to next request
    postman.setNextRequest('next_request_name')
}

Hope that helps!