# Authentication tokens

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

See [Authentication](https://ridewithgps.com/api/v1/doc/authentication.md) for when to use tokens. If you use an organization account, see [Authentication for organizations](https://ridewithgps.com/api/v1/doc/organizations/authentication.md) instead.

OpenAPI specification for these endpoints: https://ridewithgps.com/api/v1/openapi/openapi_authentication_tokens.yaml

## Creates an authentication token

`POST /api/v1/auth_tokens.json`

Creates a new authentication token for API access using user credentials.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |

### Request body (`application/json`)

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `user` | object | yes |  |
| `user.email` | string | yes | User email address |
| `user.password` | string | yes | User password |

### Response `201`

| Name | Type | Description |
| --- | --- | --- |
| `auth_token` | object |  |
| `auth_token.auth_token` | string |  |
| `auth_token.api_key` | string |  |
| `auth_token.created_at` | date-time |  |
| `auth_token.updated_at` | date-time |  |
| `auth_token.user` | object |  |
| `auth_token.user.id` | integer |  |
| `auth_token.user.first_name` | string |  |
| `auth_token.user.last_name` | string |  |
| `auth_token.user.display_name` | string |  |
| `auth_token.user.email` | string |  |
| `auth_token.user.created_at` | date-time |  |
| `auth_token.user.updated_at` | date-time |  |

### Errors

- `400` Bad request - invalid parameters
- `401` Unauthorized - invalid credentials or API key

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
  "user": {
    "email": "alex@example.com",
    "password": "{password}"
  }
}' \
  https://ridewithgps.com/api/v1/auth_tokens.json
```

### Example response

```json
{
  "auth_token": {
    "auth_token": "c0cc78875f250604f9abac97712e314c",
    "api_key": "2704a8df",
    "created_at": "2000-01-01T12:00:00Z",
    "updated_at": "2000-01-01T12:00:00Z",
    "user": {
      "id": 123,
      "first_name": "Alex",
      "last_name": "Rider",
      "display_name": "Alex Rider",
      "email": "alex@example.com",
      "created_at": "2000-01-01T12:00:00Z",
      "updated_at": "2000-01-01T12:00:00Z"
    }
  }
}
```
