> For the complete documentation index, see [llms.txt](https://docs.sportmonks.com/v3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sportmonks.com/v3/welcome/authentication.md).

# Authentication

All of our APIs require authentication. You can create API tokens in MySportmonks.

To make our first request, we’ll need to get authenticated first.

We offer two different options for passing your API token. You are free to choose between the authentication methods. You can also use both of them at the same time. Please note that both methods count towards the same rate-limiting.

* **Authenticate using a query parameter**\
  You can pass your API token by passing 'api\_token' in your request parameters, like so:

```http
https://api.sportmonks.com/v3/football/livescores?api_token=YOUR_TOKEN
```

* **Authenticate using a request header**\
  You can also pass your token via an `Authorization` header, like so:

<table><thead><tr><th>Header</th><th>Value</th></tr></thead><tbody><tr><td>Authorization</td><td><pre><code>YOUR_TOKEN
</code></pre></td></tr></tbody></table>

### Authentication examples

These examples request one page of leagues. They run server-side. Keep tokens in environment variables and never expose them in browser code, logs, or error messages.

Choose one authentication method per request. Use the raw token value in the Authorization header. Do not add the Bearer prefix.

{% tabs %}
{% tab title="Query parameter" %}

#### cURL (Bash/zsh)

Requires [cURL](https://curl.se/). Set `SPORTMONKS_API_TOKEN` in your shell first. Windows PowerShell users should use `curl.exe` and `$env:SPORTMONKS_API_TOKEN`.

```bash
curl "https://api.sportmonks.com/v3/football/leagues?per_page=1&api_token=${SPORTMONKS_API_TOKEN}"
```

#### JavaScript

Requires Node.js 18+ for built-in `fetch`. Save this code as an `.mjs` file or use it in an ES module because it uses top-level `await`.

```javascript
const token = process.env.SPORTMONKS_API_TOKEN;
if (!token) throw new Error('Set SPORTMONKS_API_TOKEN before running this example.');

const url = new URL('https://api.sportmonks.com/v3/football/leagues');
url.searchParams.set('per_page', '1');
url.searchParams.set('api_token', token);

const response = await fetch(url);
const body = await response.json();

if (!response.ok) {
  console.error(`Sportmonks request failed: HTTP ${response.status}. Inspect the response body locally after redacting any token.`);
} else {
  console.log(body);
}
```

#### Python

Requires `requests`.

```python
import os
import requests

response = requests.get(
    'https://api.sportmonks.com/v3/football/leagues',
    params={
        'per_page': 1,
        'api_token': os.environ['SPORTMONKS_API_TOKEN'],
    },
    timeout=30,
)
body = response.json()

if not response.ok:
    print(f'Sportmonks request failed: HTTP {response.status_code}. Inspect the response body locally after redacting any token.')
else:
    print(body)
```

{% endtab %}

{% tab title="Authorization header" %}

#### cURL (Bash/zsh)

Requires [cURL](https://curl.se/). Set `SPORTMONKS_API_TOKEN` in your shell first. Windows PowerShell users should use `curl.exe` and `$env:SPORTMONKS_API_TOKEN`.

```bash
curl "https://api.sportmonks.com/v3/football/leagues?per_page=1" -H "Authorization: ${SPORTMONKS_API_TOKEN}"
```

#### JavaScript

Requires Node.js 18+ for built-in `fetch`. Save this code as an `.mjs` file or use it in an ES module because it uses top-level `await`.

```javascript
const token = process.env.SPORTMONKS_API_TOKEN;
if (!token) throw new Error('Set SPORTMONKS_API_TOKEN before running this example.');

const response = await fetch(
  'https://api.sportmonks.com/v3/football/leagues?per_page=1',
  { headers: { Authorization: token } }
);
const body = await response.json();

if (!response.ok) {
  console.error(`Sportmonks request failed: HTTP ${response.status}. Inspect the response body locally after redacting any token.`);
} else {
  console.log(body);
}
```

#### Python

Requires `requests`.

```python
import os
import requests

response = requests.get(
    'https://api.sportmonks.com/v3/football/leagues?per_page=1',
    headers={'Authorization': os.environ['SPORTMONKS_API_TOKEN']},
    timeout=30,
)
body = response.json()

if not response.ok:
    print(f'Sportmonks request failed: HTTP {response.status_code}. Inspect the response body locally after redacting any token.')
else:
    print(body)
```

{% endtab %}
{% endtabs %}

### How to create a new API Token in MySportmonks

You can obtain and manage your API token in [**MySportmonks.**](https://my.sportmonks.com/api/tokens) The API token is intended for your eyes only and, as such, should be stored securely. Our tokens have no expiration date and will remain valid until you manually delete them yourself.

Follow these simple steps to generate your API token:

1. Log in to[ MySportmonks](https://my.sportmonks.com/).\
   If you do not have an account, you can create one using this link: <https://my.sportmonks.com/register>
2. Go to the API section in your dashboard. A dropdown will unfold; select 'Tokens'.
3. Enter a name for your new token in the 'Token name' field.
4. Click the "Create" button.\
   \ <img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd65aUUZEfVEXzxuKQrJQGRVyCjoDVFFIlo1LlHGciEFbAdaeU8nU7FY0zZg17RYOC7vs2IKEVCOVnkeErt0qoP889FtsxB1cpghRdzdKe_GxTEWFIG3lxaquNaQeczQ1hus1VCpg?key=rJzgPtdIjMzeOcMdJVVi4g" alt="" data-size="original">
5. Your new API token will be generated instantly and ready to use!

Note: Be sure to store your token securely after it has been created. For security reasons, it will not be shown again or stored in MySportmonks.

### My token is not working

1. Confirm the canonical URL starts with `https://api.sportmonks.com/v3/football`. Do not use `/api/v3`.
2. Use the exact `api_token` query parameter or the documented raw `Authorization` header. If `Bearer` returns `401 Invalid token provided`, remove the prefix and send `Authorization: YOUR_TOKEN`. Test one method at a time.
3. Confirm the complete token has no accidental whitespace or quotes. Tokens do not expire automatically. They remain valid until deleted.
4. Test a basic endpoint without includes or filters. Inspect both the HTTP status and the API error message or code.
5. Treat `401` as an authentication issue. Treat `403` as subscription access. Treat `429` as rate limiting, not an invalid token.
6. Verify your active subscription, league access, and add-on entitlement separately from token validity.
7. If the request works locally but not on your server, compare the deployed environment variable, URL, and outgoing `Authorization` header. Include client, proxy, and redirect behavior.

For status meanings, see [Response Codes](https://docs.sportmonks.com/v3/definitions/response-codes.md). For `429` responses and rate-limit headers, see [Rate limit](https://docs.sportmonks.com/v3/api/rate-limit.md).

When contacting support, provide the authentication method, endpoint without its token, HTTP status, API error message, and relevant IDs. Redact tokens from URLs, headers, screenshots, and logs.

### Error codes

When making a request, a code response will always be returned. The following are all possible HTTP response codes for any request made to the API:

| Code                           | Description                                                                                                                                                                                                                                                     |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **200: OK**                    | Request succeeded                                                                                                                                                                                                                                               |
| **400: Bad Request**           | It seems that some part of the request is malformed. The exact reason is returned in the response.                                                                                                                                                              |
| **401: Unauthorized**          | The request is not authenticated.                                                                                                                                                                                                                               |
| **403: Forbidden**             | Not authorized. Indicates you're attempting to access a feed that is not accessible from your plan.                                                                                                                                                             |
| **429: Too Many Requests**     | Too many requests. Check the `rate_limit` response section and rate-limit headers for the applicable limit and remaining requests.                                                                                                                              |
| **500: Internal Server Error** | <p>An internal error has occurred and has been logged for further inspection. Please email support if you are receiving this error.<br><br>Check our <a href="https://status.sportmonks.com/">status page</a> to see if we are aware of any possible issues</p> |

{% hint style="danger" %}
Directly integrating an API into the frontend of a web application can be risky as it can expose sensitive information, such as your Sportmonks API token, to potential security breaches.
{% endhint %}

To avoid this, it is best practice to use a middleware, such as a backend or proxy server, to handle all communication between the frontend and the API. This middleware acts as an intermediary, making sure your API tokens are stored securely and not exposed to users. Using middleware makes it much harder for malicious actors to access sensitive information, keeping your application more secure overall.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sportmonks.com/v3/welcome/authentication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
