# Login (POST)

Authenticate with email and password to obtain a JWT token.

## Endpoint

```
POST https://api.pocketalert.app/v1/auth/signin
```

## Request

### Headers

| Header | Required | Description |
|--------|:--------:|-------------|
| `Content-Type` | ✅ | `application/json` |

### Body Parameters

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `email` | string | ✅ | Your registered email address |
| `password` | string | ✅ | Your account password |

### Example Request

**cURL**

```bash
curl -X POST "https://api.pocketalert.app/v1/auth/signin" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "your-password"
  }'
```

**JavaScript**

```javascript
const response = await fetch('https://api.pocketalert.app/v1/auth/signin', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: 'user@example.com',
    password: 'your-password'
  })
});

const { token } = await response.json();
// Use token in Authorization header for subsequent requests
```

**Python**

```python
import requests

response = requests.post(
    'https://api.pocketalert.app/v1/auth/signin',
    json={
        'email': 'user@example.com',
        'password': 'your-password'
    }
)

data = response.json()
# Use token in Authorization header for subsequent requests
```

**PHP**

```php
$response = Http::post('https://api.pocketalert.app/v1/auth/signin', [
    'email' => 'user@example.com',
    'password' => 'your-password',
]);

$token = $response->json()['token'];
// Use token in Authorization header for subsequent requests
```

## Response

### Success Response

> **Tip: 200 OK**
>
> Authentication successful

| Field | Type | Description |
|-------|------|-------------|
| `token` | string | JWT token for API authentication |
| `email` | string | User's email address |
| `name` | string | User's display name |
| `avatar` | string | URL to user's avatar image |

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "email": "user@example.com",
  "name": "John Doe",
  "avatar": ""
}
```

### Using the Token

After obtaining the token, include it in subsequent requests:

```bash
curl -X GET "https://api.pocketalert.app/v1/messages" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
```

### Error Responses

| Status | Description |
|:------:|-------------|
| `401` | Invalid credentials |
| `422` | Validation Error — Missing email or password |

> **Tip: Recommendation**
>
> For server-side integrations, we recommend using [API Keys](https://pocketalert.app/account/apikeys) instead of JWT tokens. API keys don't expire and are easier to manage.
