Walk Every Page of an API

Hard ⏱ 18 min 35% acceptance ★★★★★ 4.5
An endpoint returns {'items': [...], 'next': url_or_null}. Write fetch_all(first_url) looping: GET the current URL, extend a results list with items, follow next until it is null — the cursor-pagination pattern behind every 'list all' SDK helper. Guard with a sane page cap (say 1000) against infinite loops.

Examples

Example 1
Input
fetch_all(url)  # 3 pages of 2 items
Output
list of all 6 items
Explanation

Pages are concatenated until next is null.

Constraints

  • Follow the next links.
  • Stop after 1000 pages regardless.

Topics

APIspagination

Companies

GitHubShopifyStripe

Hints

Hint 1

while url and pages < 1000:.

Hint 2

data.get('next') drives the loop.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.