# Create Access Token

The "Create Access Token" endpoint allows a user to generate new access and refresh tokens by providing their email and password. These tokens are essential for authenticating and authorizing API requests.

## Authentication

- Include your `x-api-key` The API key provided by GenLogs. This header must be included in the request.

## Endpoint

- **URL**: [`https://api.genlogs.io/auth/token`](https://docs.genlogs.io/auth/create-token#create-access-token)
- **Method**: `POST`

## Request Parameters

Credentials must be provided in the JSON request body.

### Recommended: JSON request body

Send `email` and `password` in a JSON body with the `Content-Type: application/json` header. No URL-encoding of special characters is needed (e.g. `1234+` can be sent as-is).

```bash
curl -X POST 'https://api.genlogs.io/auth/token/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'x-api-key: {your_api_key}' \
-d '{"email": "{email}", "password": "{password}"}'
```

Body schema:

```json
{ "email": "user@example.com", "password": "your_password" }
```

### Parameters

- `email` (string, required): The email address of the user requesting the tokens.
- `password` (string, required): The password of the user for authentication.

## Response

- **200 OK**: Successfully generated and returned the access and refresh tokens.
- **401 Unauthorized**: If the provided email, and password, resulting in a failure to create the tokens.
- **500 Internal Server Error**: If an error occurs on the server during token creation.

## Response Body

Note: The refresh token is not usable at this time. Please create a new token after your original access token has expired.

- **access_token_data** (TokenSchema): The schema representing the access token and its expiration.
  - **token** (string): The access token string used for authentication and authorization.
  - **expires** (datetime): The datetime when the access token expires.

- **refresh_token_data** (TokenSchema): The schema representing the refresh token and its expiration.
  - **token** (string): The refresh token string used to obtain a new access token.
  - **expires** (datetime): The datetime when the refresh token expires.

- **user_id** (int): The ID of the user for whom the tokens were created.
- **company_id** (int): The ID of the company associated with the authenticated user.
- **customer_name** (string): The name of the customer associated with the authenticated user.

## Request Example:

```bash
curl -X POST 'https://api.genlogs.io/auth/token/?email={email}&password={password}' \
-H 'accept: application/json' \
-H 'x-api-key: {your_api_key}'
```

### Create access and refresh tokens

Create and return new access and refresh tokens for a user based on their email and password.

**Responses:**
- **200**: Access and refresh tokens created successfully.
- **401**: Token creation failed because credentials are invalid.
- **422**: Request validation error.

### Test it

**200**: Access and refresh tokens created successfully.

```json
{
  "access_token_data": {
    "token": "text",
    "expires": "2026-07-17T13:11:30.519Z"
  },
  "refresh_token_data": {
    "token": "text",
    "expires": "2026-07-17T13:11:30.519Z"
  },
  "user_id": 1,
  "company_id": 1,
  "customer_name": "text"
}
```
