I am very new to postman and doesnt have much coding knowledge . trying to loop through the pages and get the response but i am getting response only for first loop and though its inside the loop I am unable to get the response for the other loops
var responseJson = pm.response.json();//initial response
console.log(responseJson);
pm.globals.set("NextPage" ,responseJson.nextPage );//URL is taken from the initial response
let j = responseJson.currentPage ;//current page=1
let totalPage = responseJson.totalPages;// total pages=4
const _dummy = setInterval(() => {}, 100000 );
(async function main() {
for (var i=j;i<totalPage;i++)//looping through the pages and getting the response
{
var sendReq =
{
url: pm.globals.get("NextPage"),
method: "GET",
header:
{
"Authorization":"Basic MzFlMmI0YmJhZjc4NDFmMzkxZjRjMzA3YmVmZDhkZjQ6NDVkYUFEN2JDZkY0NEJkQUJGOGY4Nzg5RDdlNmUxYzI=",
"Accept": "*/*",
"Connection": "keep-alive",
"Accept-Encoding":"gzip, deflate, br"
},
body:
{
},
};
await sendRequest(sendReq);
clearInterval(_dummy);
}
})();
function sendRequest(req) {
return new Promise((resolve, reject) => {
pm.sendRequest(req, function (err, res)
{
if(err)
{
console.log(err);
return reject(err);
}
else
{
pm.globals.unset("NextPage");// URL is reset
let jsonData = res.json() ; //getting the new response of the current page
console.log(jsonData);
pm.globals.set("NextPage" , jsonData.nextPage);//getting the Next page URL
j = jsonData.currentPage;//current page = 2 for first loop
return resolve(res);
}
})
});
}