- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pagination in Postman
Hello,
Anyone solved pagination in postman?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What problem does postman has with pagination?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
Example, if you run - organizations/:organizationId/networks
It gives you 1000 networks and I haven't found any way to handle the next pages with 1000 more.
in python its no problem - but just dont know how to activate it or fix it in postman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the response headers, you will find a "link" field specifying the links to the first, last, next, and previous "pages".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, i understand this - but is it possible to load the rest inside the postman call so the list will be complete?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a pagination solution 🙂
There is not really an easy way to do this with Postman natively, but I created a script you can add to your Collection "Tests". It will perform some magic on every API request by extracting the link string in the header.
I posted a copy of the script in my github for now.
https://github.com/dexterlabora/Meraki-Dashboard-API-Postman-Collection/blob/master/tests/pagination...
Example showing the usage with {{endingBefore}} environment variable via this script
This script is designed to handle pagination in APIs by extracting the necessary information from the Link header of the HTTP response. It then sets the startingAfter and endingBefore environment variables in Postman which can be used as query parameters for subsequent API calls to navigate through paginated data.
How to Use:
- Add this script to the "Tests" section of your Postman request or to the entire collection.
- Make an initial API call to an endpoint that supports pagination.
- /networks/:networkId/events?productType=wireless&perPage=3
- If the response contains a Link header with pagination links, the script will parse it and set the startingAfter or endingBefore environment variables.
- Use one of these environment variables in your Postman collection as a query parameter for the remaining pagination calls.
- /networks/:networkId/events?productType=wireless&perPage=3&endingBefore={{endingBefore}}
- Keep hitting "Send" until you've reached the end of the pages
Script Details:
The script primarily consists of a function parseLinkHeader that processes the Link header from the HTTP response, and a main block that checks for the presence of the Link header, extracts the pagination links, and sets the environment variables.Example of script in the Tests section
Let me know if this works for you. If it this seems like a doable solution, we could possibly add it to the Meraki collection by default.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That seems to work like a charm, just tested it on getOrganizationNetworks
It gets the last networkID of the 1000 networks, and set the startingAfter to the ID L_xxxxxxxxxxxx107400
Ending before is set to the FIRST network of the second call, is that correct? (Didnt use endingBefore)
Very good work! Thx
