Is there a way of easily testing paged responses in Postman?

I’ve been using Postman to write tests for an API and things were going well. I have been able to load the response into a object and then interrogate the object to identify is a subset of the expected search responses have been included.

The API now pages the response providing the next URL which could be used to retrieve the next page of content.

The only way I can think to pull out all of the search results is to load the URL into some sort of global variable and use the runner to re-rerun the same test, updating the next URL each time until no further URL is provided by the API. This sounds horrendous because if I’m looking for certain test results then the fulfilled results will all need to go into global environments and then checked once there are no more pages to load.

Am I missing something obvious? Is there any easier way to evaluate a paged search response?

1 Like

Have you looked at postman.setNextRequest(“Request Name”) ?
Assuming the page url is returned in a field called “pageURL”
And the request URL is saved as an environment/global variable
image

Perhaps do something like:

var response = JSON.parse(responseBody);
// Imaginge all your tests are here.
// If the value of pageURL field is NOT an empty string, hit the endpoint again instead of advancing to the next request in the colleciton.
if(response.pageURL !== "") {
  // replace the URL variable used for the request with the value of pageUrl
  postman.setEnvironmentVariable("url", response.pageUrl);
  postman.setNextRequest("Whatever this current request is called");
}
// If the pageURL is empty, postman will carry on to the next request as normal

The only thing you’d need to do is “reset” the url variable at the start or each test run so you get “page 1” first.
In our APIs, pagination is handled by using query parameters in the request name. Receiving a whole different URL based on the number of pages is a bit weird ha
So GET https://example-api-request.com/reviews?page=1

Hopefully this basic concept might be of some value to you.

2 Likes

Thanks for the advice. I thought this was the general solution but it really helps to see the example code.

So if I’m looking for 10 specific records which could be anywhere in the returned responses, I just need to set up those as global variables and tick them off when I find them, then at the end see if any remain.

You’re right, while the API provides a complete URL, it’s only the parameters that change from the original query. eg… ?_getpages=4981f5a0-d67c-45e9-9c94-a7b435a7c9a4&_getpagesoffset=10&_count=10&_pretty=true&_bundletype=searchset"

Ah ok, so it’s only the “getpages” query parameter that needs to be updated in order to get to the next page?
If so, “parameterise” that value and just pull it from the response each time.

If ALL the possible page urls are present in the response from the first request, I’d create an array of “pageurls” and also have a “counter” set to 0 before the first request is made.
Then I’d increase the counter by 1 with each request.
Then in the pre-request script tab I’d do a check that checks if the counter variable is the greater than the array lenth of pageurls then you’d know that you have tested all the page urls in your array.

At least, that’s what I’m doing at the moment until I can think of a better way of doing it xD

I know this pretty text heavy, so I’d be more than happy to show you my code if you want a more practical example.

1 Like

Hi I have a scenario where i got paged response.I would like to extract whole paged data response at one time. Is there any extract script we can write to extract all data present in all pages. The response I received is in JSON.

1 Like

From the documentation it seems that the “solution” proposed by @postman-paul540 will only work fir running a collection. Is there a way to page through the requests for running a single request?

Assuming you mean that you have paginated results, then you could do the following in your test script for that request:

  1. Check the response body to see if it indicates there are more pages
  2. If so, then repeat that request (and perform whatever operations/tests on it that you need) until the response indicates you have completed the pagination

i have issue similar to it,i have a GET request for getting the pages like http:///api/v1/vehicle/?page=1&size=10, now i want to check if some specific changes have been made in the response body so i want to go through few pages , how can i sent multiple value to the a single parameter and check if the desired change is made in the response(i want to check multiple changes) could someone help i m stuck