How to Poll Long Running Async Requests in Postman

Some HTTP requests are long running and instead of asking users to wait for the long running operation to complete, they will return a “request status URI” that, when requested, will return a running/success/failure message.

For example, when you create a new Azure IoT Hub via this request:{{api-version}}

It will return an Azure-AsyncOperation header with the following URI:

Which will have a payload like this when still running:

"status": "Running"

Or this when the IoT Hub has been created:

"status": "Succeeded"

Here’s how to deal with this scenario in Postman.

The flow of requests will be executed in this order:

1. Execute the long running request.
2. Execute the check long running request status request.
3. If still running, then delay for 30 seconds and repeat #2. If not still running, then pass or fail the request based on status returned.

Create a “Delay” Request

This will create a Postman timeout that doesn’t chew up your CPU.


“delay” is the number of minutes to delay before the next execution.


After the request is delayed it will execute this “test” which checks to see if there’s a “nextRequest” environment variable and then calls the “setNextRequest” method to execute it.

var next = postman.getEnvironmentVariable('nextRequest');
if(next !== ''){

Create Long Running HTTP request



Authorization:Bearer {{bearerToken}}

See How to Use Azure Active Directory (AAD) Access Tokens in Postman for instructions on how to get a bearer token.


"location": "West US",
"sku": {
"name": "S1",
"tier": "Standard",
"capacity": 1


This will first see if the request was successful and then put the Azure-AsyncOperation URI into an Environment Variable (to be executed later). It then sets the “nextRequest” environment variable that will be executed by

var json = JSON.parse(responseBody);
tests["Create or Update IoT Hub"] = !json.error && responseBody !== '' && responseBody !== '{}';
postman.setEnvironmentVariable("createUpdateIoTHubResponseUrl", postman.getResponseHeader("Azure-AsyncOperation"));
postman.setEnvironmentVariable("nextRequest", 'Verify Create or Update IoT Hub');
postman.setNextRequest('Verify Create or Update IoT Hub');

Setup Long Running Status Check Request

This request will call the “Azure-AsyncOperation” URI, check the status, call Delay, which will then execute the status check again.




Authorization:Bearer {{bearerToken}}


Add the following test to check the status and if still running will set the next request to ‘Delay’, which in turn will execute this request again.

var test = 'Verify Create or Update IoT Hub';
var json = JSON.parse(responseBody);
tests[test] = false;
if(json.status !== 'Running'){
tests[test] = json.status === 'Succeeded';

Execute Requests

When you execute the tests in Collection Running, the output will look like the following:

When you execute in Newman, the requests will look like the following:

Until you get a success message: