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

# Authentication

> How to authenticate your API requests

## API Key Authentication

All Data Docked API requests require authentication using an API key. Pass your API key in the `x-api-key` header with every request.

```bash theme={null}
curl -X GET "https://datadocked.com/api/vessels_operations/get-vessel-location?imo_or_mmsi=9247431" \
  -H "x-api-key: YOUR_API_KEY"
```

## Getting Your API Key

<Steps>
  <Step title="Create an account">
    Sign up at [datadocked.com/signup](https://datadocked.com/signup)
  </Step>

  <Step title="Navigate to API Keys">
    Go to your [dashboard](https://datadocked.com/dashboard/my_keys) and find the API Keys section
  </Step>

  <Step title="Copy your key">
    Copy your API key and store it securely
  </Step>
</Steps>

## Best Practices

<Warning>
  Never expose your API key in client-side code or public repositories.
</Warning>

### Keep Your Key Secure

* Store API keys in environment variables
* Use server-side code to make API requests
* Never commit API keys to version control
* Rotate keys if you suspect they've been compromised

### Environment Variables

<CodeGroup>
  ```bash Bash theme={null}
  export DATADOCKED_API_KEY="your_api_key_here"
  ```

  ```python Python theme={null}
  import os

  api_key = os.environ.get("DATADOCKED_API_KEY")
  ```

  ```javascript Node.js theme={null}
  const apiKey = process.env.DATADOCKED_API_KEY;
  ```
</CodeGroup>

## Authentication Errors

If your API key is invalid or missing, you'll receive a `401 Unauthorized` response:

```json theme={null}
{
  "error": "Unauthorized",
  "message": "Invalid or missing API key"
}
```

### Common Issues

| Error           | Cause                 | Solution                               |
| --------------- | --------------------- | -------------------------------------- |
| Missing API key | No `x-api-key` header | Add the header to your request         |
| Invalid API key | Incorrect key value   | Check for typos or use the correct key |
| Expired key     | Key has been revoked  | Generate a new key in your dashboard   |
