> For the complete documentation index, see [llms.txt](https://developers.elocal.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.elocal.com/advertiser-apis/advertiser-guides/authentication.md). Agents can also search and read this documentation through its [MCP server](https://developers.elocal.com/~gitbook/mcp).

# Authentication

## Overview

All `/advertisers/v2/` endpoints require authentication using API keys. API keys provide secure access to your data and ensure that only authorized parties can access campaign results, metadata, and other sensitive information.

**Important**: All V2 endpoints are authenticated. Unlike V1 endpoints that may have used UUID-based access, V2 requires explicit API key authentication for enhanced security.

***

## Account-Scoped Endpoints

Account-scoped endpoints include an `{accountId}` path parameter. Your API key must be associated with the account specified in the path — requests to a different account's resources will return `401 Unauthorized`.

{% hint style="info" %}
If you don't know your account ID, use the [Get Account](https://developers.elocal.com/advertiser-apis/advertiser-guides/account.md#get-account) endpoint to retrieve it from your API key.
{% endhint %}

***

## Managing API Keys

### eLocal Advertiser Portal

API keys are managed through the **eLocal Advertiser Portal**. To generate, view, or revoke API keys:

1. **Log in** to the [eLocal Advertiser Portal](https://advertisers.elocal.com/)
2. Navigate to **Settings** > **API Keys**
3. Click **Generate New API Key** to create a new key
4. Copy and securely store your API key immediately (it will only be shown once)
5. Manage existing keys: view details, revoke access, or rotate keys as needed

### API Key Format

All eLocal API keys follow this format:

```
eloc_<random_string>
```

Example: `eloc_abc123def456ghi789jkl012mno345`

### Security Best Practices

* **Never commit API keys to version control**: Use environment variables or secure credential management systems
* **Rotate keys regularly**: Generate new keys periodically and revoke old ones

***

## Authentication Methods

You can authenticate API requests using either the `Authorization` header (recommended) or the `X-API-Key` header. Both methods are supported across all V2 endpoints.

### Method 1: Authorization Header (Recommended)

Pass your API key as a Bearer token in the `Authorization` header:

```http
Authorization: Bearer eloc_your_api_key_here
```

**Example with curl:**

```bash
curl -X GET "https://apis.elocal.com/advertisers/v2/metadata" \
  -H "Authorization: Bearer eloc_abc123def456ghi789jkl012mno345"
```

***

### Method 2: X-API-Key Header (Alternative)

Alternatively, pass your API key directly in the `X-API-Key` header:

```http
X-API-Key: eloc_your_api_key_here
```

**Example with curl:**

```bash
curl -X GET "https://apis.elocal.com/advertisers/v2/metadata" \
  -H "X-API-Key: eloc_abc123def456ghi789jkl012mno345"
```

***

## Changelog

### Version 2.0 (Current)

* Introduction of API key authentication for all V2 endpoints
* Support for `Authorization: Bearer` and `X-API-Key` header methods
* API key management via eLocal Advertiser Portal
