The Money S5 API uses authentication based on the **OAuth2** standard. Keys are generated in the Money environment under *Administration – Data Exchange – REST API – API Keys*. A key is associated with a Money user, whose permissions for endpoints are defined.

## Authentication methods

The following methods can be used as the authentication type:

- **Client credentials**

- **Authorization code**

Each request must include the header:
`Authorization: Bearer [access_token]`

![Image](/uploads/docs/20260813-125456-e2d75695023c4ff28446960cae970d8a.png)![Image](/uploads/docs/20260813-125512-97a9114da2204558870cd4cc7bfee973.png)

Keys can be created using the **Generate** button in the top bar, or simply entered manually.

![api_klice_generovani-768x768](/uploads/docs/20260813-125603-1baae974edb6431cbd6a7a12b4725d77.png)

API permissions are managed using a separate Money user and their API role. Permissions can be used to restrict the usual view, add, edit, and delete rights, including more detailed filters for individual lists.

### Client credentials

Request to the */token* endpoint

`POST http(s)://[adresa API]/connect/token`

`Content-Type: application/x-www-form-urlencoded`

`grant_type=client_credentials&client_id=[vygenerované Client ID]&client_secret=[vygenerované Client Secret]&scope=S5Api`

The identity server returns the generated token (JSON):
`{„access_token“:“[vygenerovaný token]“,“expires_in“:3600,“token_type“:“Bearer“}`

:::callout {type="warning"}

If an incorrect token is used in a request, or the token has expired, S5API returns a 401 Unauthorized error for that request. The token is generated with a validity period of 3600 seconds, or 1 hour. The token validity value is set in [config.json](https://docs.moneyerp.com/developer/konfigurace-formulare#soubor-config-json).

:::

![postman_auth](/uploads/docs/postman_auth.png)

**Token**
The token can be decoded to view its contents, for example here: [https://jwt.io/](https://jwt.io/).

### Authorization code

Request to the */authorize* endpoint

`GET http(s)://[adresa API]/connect/authorize?client_id=[vygenerované Client ID]&response_type=code&redirect_uri=http://[adresa API]/oauth2-redirect.html&scope=S5Api offline_access`

**redirect\_uri** – the address to which the authorization code is sent after the user signs in; this code is exchanged for an access token. The address must be assigned to the client in S5.

Request to the */token* endpoint

`POST http(s)://[adresa API]/connect/token`

`Content-Type: application/x-www-form-urlencoded`

`grant_type=authorization_code&client_id=[vygenerované Client ID]&client_secret=[vygenerované Client Secret]&scope=S5Api&code=[autorizační kód vrácený v předchozím kroku]&redirect_uri=http://[adresa API]/oauth2-redirect.html`

The identity server returns the generated token (JSON):

`{„access_token“:“[vygenerovaný token]“,“expires_in“:3600,“token_type“:“Bearer“,“refresh_token“: „[vygenerovaný refresh token]“}`

**code** – the authorization code returned after redirection to redirect\_uri (the code can be used only once)

**redirect\_uri** – the address specified in the request to the authorize endpoint

**Scope**: S5Api offline\_access

## Refreshing token validity

`POST http(s)://[adresa API]/connect/token`

`Content-Type: application/x-www-form-urlencoded`

`grant_type=refresh_token&client_id=[vygenerované Client ID]&client_secret=[vygenerované Client Secret]&scope=S5Api&redirect_uri=http://[adresa API]/oauth2-redirect.html&refresh_token=[vygenerovaný refresh token]`
