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.