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

158
Visualizações
Loop Requests w/ env variables until JSON Array is Complete

I'd like to loop through a Postman Collection of 3 API Requests until the JSON Array is complete.

For example, I have a Collection of 3 Requests (below) called Compass:

Compass (Collection Name)
    POST Create Submission
    GET Retrieve Submission
    DEL Delete Submission
    

In my Collection called Compass, I have a Pre-Request Script that sends a Request for 10 UUID's (below). I'm able to store the 10 UUID's from the Response into a JSON Array in hopes to later iterate through the array via a Looping the collection until the array is complete. The UUIDs are saved as a Environment Variable called 'ids'.

Pre-Request Script:

pm.sendRequest({
    url: "https://www.uuidgenerator.net/api/version1/10",
    method: 'GET',
}),
    pm.test("UUIDs"), function() {

    let response = pm.response.text().split('\n'), jsonObject = {}
response.forEach((item,index)=>{
    jsonObject[`UUID_${index}`] = item });

console.log(jsonObject)
pm.environment.set("ids", jsonObject)
};

My goal is to iterate 1 UUID at a time through the collection. So, the Same UUID goes through the Create Submission, Receive Submission and Delete Submission, and once that completes, the next UUID in the array will loop, Once the array of 10 UUID's is done, it will stop the Collection Loop.

The body of the Requests has a bunch of data but ultimately I just have put the ID variable in the value spot of the "id" key, like so: (Quotes because it must be a String)

"id":"{{ids}}",

Also in the First Request (Create Submission) I have a Pre-request that sends to the following Request (Receive Submission) if the length of the env variable is create than 0.

pm.environment.get("ids");
if (ids.length < 0){
    postman.setNextRequest("Create Submissions");
} else {
    pm.setNextRequest(null)
}

I've also plugged this into the Test field to see what populates:

var uuids = pm.environment.get("ids")

console.log(uuids)

And in the Response I'm receiving a null ?

POST https://XXXXX/submissions
null

It doesn't seem the environment variable is being called from the Pre-request script.

I'm sure I'm iterating through this incorrectly and probably need to figure out a better function that goes through the Array one by one. I also wonder if I'm putting these Scripts in the wrong places.

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