Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
The response is displayed only for the first loop when I use sendrequest in a loop in postman

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);
                }
               })
      });

    }

enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!