# Responses and errors

> Documentation index: https://ridewithgps.com/api/v1/doc/llms.txt

## Responses

API responses always contain a root key named after the requested resource(s):

```json
// 200 - OK
{
  "route": {
    "id": 123,
    "name": "Forest Park loop",
    // ...
  }
}
```

## Pagination

Some requests (like the routes index request at `/api/v1/routes.json`) support pagination with `?page={page}&page_size={page_size}` query parameters. Page sizes must be between 20 and 200. If you do not send a page size, you get the default for that request. Pagination metadata is included in the response:

Endpoint: [Returns a list of routes](https://ridewithgps.com/api/v1/doc/endpoints/routes.md)

```json
// GET /api/v1/routes.json?page=1&page_size=20
// 200 - OK
{
  "routes": [
    // ...
  ],
  "meta": {
    "pagination": {
      "record_count": 207,
      "page_count": 11,
      "page_size": 20,
      "next_page_url": "https://ridewithgps.com/api/v1/routes.json?page=2&page_size=20"
    }
  }
}
```

* A `null` value of `next_page_url` indicates that you have reached the last page of results.

## Error responses

A successful request returns a `200 - OK`, `201 - Created` or `204 - No Content` status code.

When reporting an error, the API responds with one of the following status codes:

* `400 - Bad Request` - malformed request
* `401 - Unauthorized` - authentication is required and has failed
* `403 - Forbidden` - authenticated user lacks required permissions
* `404 - Not Found` - the requested resource cannot be found
* `422 - Unprocessable Entity` - request is unable to be processed
* `500 - Internal Server Error` - an unexpected condition was encountered

In case of errors, the response body includes an array of error messages:

```json
// 401 - Unauthorized
{
  "errors": ["Authentication is required and has failed"]
}
```

```json
// 422 - Unprocessable Entity
{
  "errors": ["name is required", "start_date is required"]
}
```
