Hi all,
I have spent a few evenings stuck on the 'Day 09’ challenge, specifically step 3.send.1 (4). I can see that the request increments the pageNumber
variable each time there is another page available, but the call only returns one page of results and doesn’t appear to run the postman.setNextRequest('get starships');
portion and cycle through the remaining pages until nextRequest == null
.
I expect that this is an easy thing to fix but I’ve been staring at it for so long that I can’t see for the wood for the trees and needed a fresh pair of eyes.
The specific step is below:
- Add another script to set the next request called to be the
get starships
request if the next page is available, so that running this folder in its entirety would page through all the starships in order until there are no more pages available.
let response = pm.response.json();
console.log(response.count)
let nextRequest = response.next;
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.variables.set(`nextRequest`, nextRequest);
let currentPage = pm.collectionVariables.get(`pageNumber`)
if(nextRequest !== null){
currentPage++;
pm.collectionVariables.set(`pageNumber`, currentPage);
//console.log(pm.collectionVariables.get(`pageNumber`))
postman.setNextRequest(`get starships`); // This bit is not working
}
//pm.collectionVariables.set(`pageNumber`, 1); // To reset the collection variable
If I used a While
statement (which seems the most obvious to use here), the pageNumber
variable doesn’t increment. When running the code above as it, the response takes ~30 seconds and only returns 10 results (the first page) out of the total 36.
I’ve already tried: While statements, Do-While statements, scoured every related article in the forum and across the web but to no avail.
Thank you