> This page is for API.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.eon.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.eon.io/_mcp/server.

# Get Access Token (OAuth 2)

POST https://%7Baccount-domain%7D.console.eon.io/api/v1/oauth2/token
Content-Type: application/x-www-form-urlencoded

Retrieves an access token using an OAuth-2.0-compliant flow.
Accepts form-encoded credentials using standard `client_id` and `client_secret` field names.

This method is specifically designed for OAuth 2.0 clients like Grafana that send credentials as form-encoded data.
For JSON-based API calls, use [Get Access Token].

The client ID and secret you provide when calling this method must be from a set of API credentials from your Eon account.
To learn more about creating API credentials and completing the authentication flow, see [Authentication](/api/using-the-api/authentication).

The returned access token has the permissions included in the role you assigned to the API credentials.
Always make sure the API credentials have the permissions needed for the API methods you want to use it for.

The access token is valid for 12 hours.
After that, you must call this method again to get a new token.

[Get Access Token]: ./get-access-token


Reference: https://docs.eon.io/api/api-reference/auth/get-access-token-o-auth-2

## Request

### Body (application/x-www-form-urlencoded)

This endpoint expects an OAuth2TokenRequest.

- `client_id` (string, required) — API client ID.
- `client_secret` (string, required) — API client secret.
- `grant_type` (enum, required) — The OAuth 2.0 grant type you're using. Must be `client_credentials`.
  - Allowed values: `client_credentials`

## Response

### 200

Authenticated

- `access_token` (string, optional) — Access token, which you pass in the `Authorization` header when calling API methods.
- `token_type` (string, optional) — Type of the token, which is always `Bearer`.
- `expires_in` (integer, optional) — Length of time until the token expires, in seconds. Default: `43200` (12 hours).

## Errors

### 404 Not Found Error

API credentials not found.

- `error` (string, optional)

## Examples

**Request**

```json
{
  "client_id": "rachelyaf5cbxibLiu22yw2t5ezeozxu5itv43uw2tyn3xpqprta",
  "client_secret": "eon_sample008789765400caf772b8e1b69de703792ba12c9eadef689725e0489324a093a64b4459ffecbaaa441c377950628b6b9042af728056d1d060b8f5d5sample",
  "grant_type": "client_credentials"
}
```

**Response**

```json
{
  "access_token": "string",
  "token_type": "Bearer",
  "expires_in": 43200
}
```

**SDK Code**

```python
import requests

url = "https://{account-domain}.console.eon.io/api/v1/oauth2/token"

payload = ""
headers = {"Content-Type": "application/x-www-form-urlencoded"}

response = requests.post(url, data=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://{account-domain}.console.eon.io/api/v1/oauth2/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams('')
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://{account-domain}.console.eon.io/api/v1/oauth2/token")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .asString();
```