Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda