$http.post requests sent syncronyously (one by one)

Hi,
I’m tyring to implement scripted API monitor to send requests in some specific order.
So i need these requests to be sent syncronyously one by one. Is there any way to do this? I need specific order to be able to extract some data from response body of first request and put it in second.

//This request should be sent first
$http.post(
		{
      url: {url1},
      body: {body1},
      headers: {headers1},
		},
  	function callback(error, response, body) { 
    	assert.ok(response.statusCode == 200, 'Expected 200 OK response');
		}
);

//This request should be sent second after first is completed
$http.post(
		{
      url: {url2},
      body: {body2},
      headers: {headers2},
		},
  	function callback(error, response, body) { 
    	assert.ok(response.statusCode == 200, 'Expected 200 OK response');
		}
);

The solution is quite simple:

//This request should be sent first
$http.post(
{
url: {url1},
body: {body1},
headers: {headers1},
},
function callback(error, response, body) {
assert.ok(response.statusCode == 200, ‘Expected 200 OK response’);

//This request should be sent second after first is completed
$http.post(
{
url: {url2},
body: {body2},
headers: {headers2},
},
function callback(error, response, body) {
assert.ok(response.statusCode == 200, ‘Expected 200 OK response’);
});
}
);

Hi @Oleg_Musienko

You may also want to review my templated script for testing API’s.

Hi @Oleg_Musienko,

glad you found a solution to this.

Being Synthetics runtime a Node runtime, it’s async by nature. But it’s all callback/promises driven.
So, easily, you just put “step 2” into the callback of “step 1” and get the order you want.

Ivan