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

# Authentication

> Get an access token with your API credentials and use it to call the API.

The API uses the OAuth 2.0 **client credentials** flow. You exchange your API credentials (a client ID and client secret) for an access token, then send that token with every API request.

> [!CAUTION]
>
> Your client secret grants access to your network's data. Only use it from your servers: **never** put it in a browser, mobile app, or any other client-side code.

## Create API credentials

**1. Open the Developers page**

Log in to [**Network Manager**](https://energy.nayax.com) and go to **Settings** > [**Developers**](https://energy.nayax.com/settings/developers).

**2. Create the credentials**

Under **Create API credentials**, enter a name that tells you where they're used (for example, `Fleet integration`) and select **Create API credentials**.

**3. Save the client secret**

Copy the **client ID** and **client secret** and store them somewhere safe, such as your secrets manager.

> [!WARNING]
>
> The client secret is shown **only once**. If you lose it, create new credentials, switch your integration to them, and delete the old ones.

## Request an access token

Send a `POST` request to the token URL:

```
https://api-auth.energy.nayax.com/oauth2/token
```

> [!NOTE]
>
> Using the API in QA? Request tokens from `https://api-auth.qa.energy.nayax.com/oauth2/token` instead.

* **Body:** `grant_type=client_credentials`, sent **form-encoded** (`Content-Type: application/x-www-form-urlencoded`). A JSON body is rejected with `415 Unsupported Media Type`.
* **Credentials:** your client ID and client secret, as HTTP Basic authentication (recommended), or as `client_id` and `client_secret` fields in the body.
* **Don't send `scope`.** Your token always carries all the scopes your credentials were given; requesting one returns `invalid_scope`.

```bash curl theme={null}
curl --request POST \
  --url https://api-auth.energy.nayax.com/oauth2/token \
  --user "$CLIENT_ID:$CLIENT_SECRET" \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials
```

```javascript Node.js theme={null}
const response = await fetch('https://api-auth.energy.nayax.com/oauth2/token', {
  method: 'POST',
  headers: {
    Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`,
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: new URLSearchParams({ grant_type: 'client_credentials' }),
});
const { access_token, expires_in } = await response.json();
```

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

response = requests.post(
    "https://api-auth.energy.nayax.com/oauth2/token",
    auth=(client_id, client_secret),
    data={"grant_type": "client_credentials"},
)
token = response.json()["access_token"]
```

**Example response:**

```json theme={null}
{
  "access_token": "eyJraWQiOiJ...",
  "expires_in": 86400,
  "token_type": "Bearer"
}
```

## Call the API

Send the token in the `Authorization` header of every request:

```bash theme={null}
curl --request GET \
  --url https://api.lynkwell.com/asset-management/v1/assets \
  --header "Authorization: Bearer $ACCESS_TOKEN"
```

## Reuse tokens until they expire

A token is valid for **24 hours** (`expires_in` is in seconds). Request one, cache it, and reuse it for every API call until shortly before it expires. Don't request a new token per API call.

## Token request limits

Each set of API credentials can request at most:

| Window | Limit | Resets |
| - | - | - |
| Hour | **60 tokens** | At the top of each hour (UTC) |
| Day | **500 tokens** | At midnight UTC |

Past either limit, the token URL answers `400` with an error saying the hourly or daily token quota is exceeded, until that window resets. Tokens you already have keep working.

An integration that reuses its token for its 24-hour lifetime needs about one token a day. If you run several servers or workers, share one token between them (for example, through a cache) rather than requesting one in each.

## Errors

| Response | Cause |
| - | - |
| `400` `invalid_client` or `invalid_grant` | Wrong or missing client ID or client secret, or the credentials were deleted |
| `400` `invalid_scope` | The request included a `scope` parameter |
| `400` quota exceeded | Too many tokens requested in the past hour or day |
| `415 Unsupported Media Type` | The body was sent as JSON instead of form-encoded |
| `401` from an API | No token was sent, or the token is malformed or expired, or its credentials were deleted |
| `403` from an API | The token doesn't have the scope that endpoint needs |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.