I am writing a test script in Postman 9 and want to call the API and page the API response until all results are returned. For this API, pagination works by passing the next page id in the API request parameters until the has more flag is set to false.
At the moment it adds the parameter but then appears to lose it on the 2nd call. Code sample below:
var myIsMore = true
var myCount = 0;
var myResponse ='';
let myRequest =
{
url: 'https://api.mysite.com/products'
}
while (myIsMore == true)
{
pm.sendRequest(myRequest, function (err, myResponse)
{
myResponse = myResponse.json();
myCount = myCount + myResponse.data.length;
myIsMore = myResponse.has_more;
pm.request.url.addQueryParams(['nextPage=' + myResponse.data[myCount-1].next])
});
}
Thanks for any help