> ## Documentation Index
> Fetch the complete documentation index at: https://docs.postsyncer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Learn how to authenticate your API requests with PostSyncer

# Authentication

All PostSyncer API requests require authentication using an API key. This guide explains how to obtain and use your API key.

<Note>
  Don't have an API key yet? [Get one here](https://app.postsyncer.com/dashboard?action=settings\&section=api-integrations).
</Note>

## Getting Your API Key

1. **Sign in** to your PostSyncer account at [app.postsyncer.com](https://app.postsyncer.com)
2. **Navigate** to [Settings → API Integration](https://app.postsyncer.com/dashboard?action=settings\&section=api-integrations)
3. **Click** "Create"
4. **Copy** the key immediately - it won't be shown again

<Warning>
  Keep your API key secure and never share it publicly. If your key is compromised, regenerate it immediately.
</Warning>

## Using Your API Key

Include your API key in the `Authorization` header of all requests:

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

### Example Request

```bash theme={null}
curl -X GET "https://postsyncer.com/api/v1/workspaces" \
  -H "Authorization: Bearer 11|HzNfjB..." \
  -H "Content-Type: application/json"
```

### JavaScript Example

```javascript theme={null}
const response = await fetch('https://postsyncer.com/api/v1/workspaces', {
  headers: {
    'Authorization': 'Bearer 11|HzNfjB...',
    'Content-Type': 'application/json'
  }
});
```

### Python Example

```python theme={null}
import requests

headers = {
    'Authorization': 'Bearer 11|HzNfjB...',
    'Content-Type': 'application/json'
}

response = requests.get('https://postsyncer.com/api/v1/workspaces', headers=headers)
```

### Python Example

```python theme={null}
import requests

headers = {
    'Authorization': 'Bearer 11|HzNfjB...',
    'Content-Type': 'application/json'
}

response = requests.get('https://postsyncer.com/api/v1/workspaces', headers=headers)
```

### PHP Example

```php theme={null}
$headers = [
    'Authorization: Bearer 11|HzNfjB...',
    'Content-Type: application/json',
];

$ch = curl_init('https://postsyncer.com/api/v1/workspaces');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    $data = json_decode($response, true);
    print_r($data);
}

curl_close($ch);
```

## Error Responses

If authentication fails, you'll receive a `401 Unauthorized` response:

```json theme={null}
{
  "message": "Unauthenticated."
}
```

Common authentication errors:

| Error Code                             | Description                               |
| -------------------------------------- | ----------------------------------------- |
| `Unauthenticated.`                     | Invalid or missing API key                |
| `Expired`                              | API key has expired                       |
| `Forbidden - Insufficient permissions` | API key doesn't have required permissions |
