Hi Team,
I am trying to get all the pages from API.
We have 71 pages in our API. So, I wanted to use loop to print all the pages in postman.
So, I got the total page and page number from JSON API. I used it in a for loop along with the send request.
However, I did not get expected results. It just prints the page 1.
Also, I tried to change page parameter manually. That works.
But, when I try to script it. It does not change the page number.
Please advise on how to do this.
Sample script.
let jsondata = pm.response.json();
let page_number = jsondata.headers.page_info.page_number;
let total_page = jsondata.headers.page_info.total_page;
for(let I=page_number; I<=total_page;I++)
{
//console.log(I);
pm.sendRequest({
url: āā,
method: āGETā,
headers:{
page_info: {page_number:I}
},
body: {
mode: 'raw',
raw: JSON.stringify({ key: jsondata })
}
}, function (err, res) {
console.log(res);
});
}
Also, I tried to just use simple loop to get all the page numbers and pass that value in a variable to the headers using {{I}} this syntax. However, no success.
My Requirement is to get all the records from all the pages and save the json file.
Header Structure:
Thanks,
Jinal