Hi folks, I’m a newbie in Postman; I’m working on automating more than 100 get requests to different addresses; now, the automation is ok only if I create a single Get request for each address, but I would like to create a single Get request passing an array of addresses as JSON o directly in the script. I tried to do it by passing an array in the script, but I got an error. I don’t found anything about it in the Postman documentation, someone can help me?
This is my code in the Scripts section (post-response):
// Array of addresses to test
const addresses = [
'http://address1',
'http://address2',
'http://address3'
];
// Function to send requests for all addresses
function sendRequests(addresses) {
addresses.forEach((address, index) => {
pm.sendRequest(address, function (err, response) {
// Log the request and response
console.log(`Request #${index + 1}: ${address}`);
console.log(`Response Status Code: ${response.status}`);
console.log(`Response Body: ${response.text()}`);
// You can also add your assertions here
pm.test(`Request #${index + 1} should return a 200 status code`, function () {
pm.expect(response.status).to.eql(200);
});
});
});
}
// Call the function to send the requests
sendRequests(addresses);
/**
pm.test("Status test", function () {
pm.response.to.have.status(200);
});
*/
As address in the GET request I have the global variable {{urls}}.
When I try to Send the request I have the error: Error: getaddrinfo ENOTFOUND {{urls}}
Error: getaddrinfo ENOTFOUND {{urls}}
Request Headers
User-Agent: PostmanRuntime/7.41.0
Accept: /
Postman-Token: aecda7ac-2054-4611-968b-2d1b6af12852
Host: {{urls}}
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Request Body