Using array from environment variable for request body in postman

I’m trying to loop through the list to fill in all the fields.
I don’t know how to do this, I’m still learning.

Can you help me?

var jsonData = JSON.parse(responseBody);
var count = 0;

for (var i = 0; i<jsonData.value.length; i++) {

if ((jsonData.value.json()[i]=="cpf"))
{
    postman.environment.set("cpf", jsonData.value[i].cpf);
}

count++;

}

I managed to do what you need, thanks.

var jsonData = JSON.parse(responseBody); for (var i = 0; i < jsonData.length; i++) { pm.environment.set(“nome”, jsonData[i][“nome”]); }

Hi @andersonpsilva

Here is something similar I was playing with recently;

var response = pm.response.json();

for (let i = 0; i < response.tags.length; i++) {
    console.log("value is " + response.tags[i].name + " and index is " + i)
    if(response.tags[i].name === "string"){
        console.log("value is " + response.tags[i].name + " and index is " + i)
        pm.environment.set("value", i);
    }
}

Hope it helps…

1 Like