Paging
You can see executable examples of paging inthis user-contributed Jupyter notebook!
Basic paging
Use thepage
query parameter to control which page of results you want (egpage=1
,page=2
, etc). By default there are 25 results per page; you can use theper-page
parameter to change that to any number between 1 and 200.
Get the 2nd page of a list:
https://api.openalex.org/works?page=2
Get 200 results on the second page:
https://api.openalex.org/works?page=2&per-page=200
Basic paging only works to get the first 10,000 results of any list. If you want to see more than 10,000 results, you'll need to usecursor paging.
Cursor paging
Cursor paging is a bit more complicated thanbasic paging, but it allows you to access as many records as you like.
To use cursor paging, you request a cursor by adding thecursor=*
parameter-value pair to your query.
Get a cursor in order to start cursor pagination:
https://api.openalex.org/works?filter=publication_year:2020&per-page=100&cursor=*
The response to your query will include anext_cursor
value in the response'smeta
object. Here's what it looks like:
{"meta": {"count":8695857,"db_response_time_ms":28,"page":null,"per_page":100,"next_cursor":"IlsxNjA5MzcyODAwMDAwLCAnaHR0cHM6Ly9vcGVuYWxleC5vcmcvVzI0ODg0OTk3NjQnXSI=" },"results": [// the first page of results ]}
To retrieve the next page of results, copy themeta.next_cursor
value into the cursor field of your next request.
Get the next page of results using a cursor value:
https://api.openalex.org/works?filter=publication_year:2020&per-page=100&cursor=IlsxNjA5MzcyODAwMDAwLCAnaHR0cHM6Ly9vcGVuYWxleC5vcmcvVzI0ODg0OTk3NjQnXSI=
This second page of results will have a new value formeta.next_cursor
. You'll use this new value the same way you did the first, and it'll give you the second page of results. To getall the results, keep repeating this process untilmeta.next_cursor
is null and theresults
set is empty.
Besides using cursor paging to get entities, you can also use it ingroup_by
queries.
Don't use cursor paging to download the whole dataset.
It's bad for you because it will take many days to page through a long list like /works or /authors.
It's bad for us (and other users!) because it puts a massive load on our servers.
Instead, download everything at once, using theOpenAlex snapshot. It's free, easy, fast, and you get all the results in same format you'd get from the API.
Last updated