# Pagination and Error Handling

## Pagination

If all the results cannot be returned in a single request on a list endpoint, you'll have to paginate and make multiple requests. The result contains a `pagination` field:

```json
{
  "data": [{ ... }]
  "pagination": {
    "hasNextPage": true,
    "nextPageCursor": "MTA0"
  };
}
```

If `hasNextPage` is true, you can get more data by passing the `nextPageCursor` into another request. Keep all of the other parameters the same as in the previous request.

```sh
curl "https://api.getflipturn.com/api/charging-sessions?startTimeAfter=2023-03-24T01:18:05.000Z&nextPageCursor=MTA0" -H "Authorization: Bearer {api_key}"
```

Once you see `"hasNextPage": false`, then there is no more data to retrieve.

## Rate Limits

Each API key is limited to making 200 requests per minute. When fetching charging sessions with the includeIntervals query parameter, the API key is limited to 1 concurrent request. Certain endpoints enforce stricter rate limits, such as charger health. If you need a higher rate limit, please get in touch and we can discuss the use case.

## Errors and Response Codes

When the API is not able to return a successful response, it will return an HTTP response code of 400 or above, along with an error message. Response codes in the 400 category indicate an issue with the request, and 500 indicates an internal issue on Flipturn's side.

For example, this request with an incorrect API key:

```sh
curl "https://api.getflipturn.com/api/charging-sessions" -H "Authorization: Bearer invalid_key"
```

Would result in a response like the following:

```
Status code: 401

Response:
{
  "error": "Invalid API key"
}
```

Here are some errors you can get:

* `400` - invalid parameters passed to API endpoint
* `401` - invalid API key or Authorization header
* `404` - endpoint doesn't exist
* `429` - exceeded rate limit


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-docs.getflipturn.com/pagination-and-errors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
