I am in a situation where I need to run a request (lets say request C) based on the responses of request A and B. Here A is a GET & B is a POST request. Now I have tried to use pm.sendRequest twice in pre-request tab of C. But the problem I am facing mainly is, B is running ahead of A all the time. That means POST is running before GET. As a result I am unable to successfully run request C.
Here is a sample of my pre request script:
const getOTP = {
method: 'GET',
url: `${pm.environment.get('base_url')}/${pm.environment.get('common_path')}/otp-login?msisdn=${pm.environment.get('msisdnWhite')}`,
header: {
'User-Agent': 'something..',
'Accept-Language' : 'en'
},
};
setTimeout(15000)
const postOTP={
method : 'POST',
url : `${pm.environment.get('base_url')}/${pm.environment.get('common_path')}/otp-login`,
header: {
'Content-Type':'application/json',
'Accept-Language':'en'
},
body:{
mode : 'application/json',
raw: JSON.stringify(
{
"msisdn":"123456789",
"otp":"0000"
} )
}
};
pm.sendRequest(getOTP, (err, response) => {
const jsonResponse = response.json();
pm.environment.set("GETOTP",jsonResponse.result)
console.log(jsonResponse);
});
pm.sendRequest(postOTP, (err, response) => {
const jsonData = response.json();
pm.environment.set("access_token",jsonData.access_token)
});