Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hasnain_nisan's avatar

How to paginate data from a 3rd party api

I am working on a project where i get data from mediastack api, it is a news api.

when i fetch data from api it gives a json format with pagination object and data array containing different objects. By default the api limit is set to 25, means it only show 25 result with pagination object.

now how can i paginate the data help me

json snippet

"pagination": { "limit": 25, "offset": 0, "count": 25, "total": 6860 }, "data": [ { "author": "Reuters", "title": "'Pray floods don't kill us': A day on Rohingya's remote Bangladesh island", "description": "'Pray floods don't kill us': A day on Rohingya's remote Bangladesh island", "url": "https://www.investing.com/news/world-news/pray-floods-dont-kill-us-a-day-on-rohingyas-remote-bangladesh-island-2376819", "source": "Investing.com | Stock Market Quotes & Financial News", "image": "https://i-invdn-com.akamaized.net/trkd-images/LYNXMPEGBS0PQ_L.jpg", "category": "business", "language": "en", "country": "us", "published_at": "2020-12-29T14:50:19+00:00" },

0 likes
6 replies
hasnain_nisan's avatar

i got it, but dont know the process

please describe the process in details

thank you

bugsysha's avatar

Depends on the implementation of that specific API you are communicating with, but usually you can send offset parameter with your request and that will affect the API results to display new set of values.

hasnain_nisan's avatar

i got the point and i tried it with the api by adding offset=something and it works fine,

but i in deep trouble how to implement it in my laravel project

bugsysha's avatar

You loop while the offset is less than total.

1 like

Please or to participate in this conversation.