Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda