Pagination on Self-Service APIs
Amadeus for Developers Self-Service APIs can often return a lot of results. For example, when calling the Safe Place API, you may get a response hundreds of pages long. That's where pagination comes in. Using pagination, you can split the results into different pages to make the responses easier to handle.
Not all Amadeus Self-Service APIs support pagination. The following APIs currently support pagination:
- Points of Interest
- Airport Nearest Relevant
- Airport & City Search
- Flight Most Travelled Destinations
- Flight Most Booked Destinations
Accessing paginated results
Using SDKs
Amadeus for Developers SDKs make it simple to access paginated results. If the API endpoint supports pagination, you can get page results using the the .next
, .previous
, .last
and
.first
methods.
Example in Node
:
If a page is not available, the response will resolve to null
.
The same approach is valid for other languages, such as Ruby
:
In this case, the method will return nil
if the page is not available.
Manually parsing the response
The response will contain the following JSON
content:
You can access the next page of the results using the value of meta/links/next
or
meta/links/last
node within the JSON response.
Note that indexing elements between pages is done via the page[offset]
query
parameter. For example, page[offset]=18
. The next
and last
returned in the example above encode the special characters []
as %5B
and %5D
. This is called percent
encoding and is used to
encode special characters in the url parameter values.