> For the complete documentation index, see [llms.txt](https://help.citrusad.com/retail-media-interface/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.citrusad.com/retail-media-interface/integration/it/data-api/api-overview/oauth-20-authentication.md).

# Autenticazione OAuth 2.0

{% hint style="info" %}
OAuth 2.0 è disponibile solo sull'endpoint /ads

Quando si integra la reportistica sugli ordini tramite API, sarà necessario integrare l'endpoint /orders con l'autenticazione Basic e la chiave API segreta.
{% endhint %}

## Client ID e Client Secret

Il `client_id` e il `client_secret` verranno forniti dal Technical Account Manager. Il Client Secret è privato e non deve essere condiviso.

## Richiesta di Token di accesso

Per ottenere un Access Token, è necessario inviare una richiesta contenente il `client_id` e `client_secret`. Per farlo, il Retailer deve effettuare una richiesta POST all'endpoint dell' Epsilon Retail Media Authorization Server:

```http
https://$BASE_URL/v1/oauth2/token
```

{% hint style="info" %}
`/oauth2/token` fornisce solo il token pertinente. Utilizzerai questi token per interagire con i vari endpoint di integrazione.
{% endhint %}

La richiesta richiederà un'autorizzazione Basic inviata tramite l'intestazione di richiesta Authorization contenente i dati del Retailer `client_id` e `client_secret` codificati in base64:

`Authorization: "Basic" + base64encode(client_id + ":" + client_secret)`

È necessario aggiungere il seguente parametro utilizzando il formato `application/x-www-form-urlencoded` nel corpo della richiesta HTTP:

`grant_type=client_credentials`

La richiesta sarà simile alla seguente:

```http
POST https://$BASE_URL/v1/oauth2/token
Content-Type: application/x-www-form-urlencoded
Authorization: Basic <base64 encoded id+key>
grant_type=client_credentials
```

## Ricezione dell'Access Token

La risposta conterrà le seguenti informazioni

* `access_token`: L'access token da utilizzare quando si chiamano le Epsilon Retail Media API
* `expires_in`: Il tempo, in secondi, prima della scadenza dell'access token
* `token_type`: Il tipo di token restituito. In questo caso sarà sempre Bearer

Di seguito è riportato un esempio di risposta

```json
{
  "access_token": "xxxxx.yyyyy.zzzzz",
  "expires_in": 3600,
  "token_type": "Bearer"
}
```

## Utilizzo del Token

Le chiamate agli endpoint dell'API Epsilon Retail Media possono essere effettuate semplicemente aggiungendo l'Access Token generato all'intestazione Authorization della richiesta `Authorization: “Bearer “ <access_token>`

```http
POST $BASE_URL/v1/ads/generate HTTP/1.1
accept: application/json
content-type: application/json
Authorization: Bearer <access_token>
{
    "customerId": "wertg5432a",
    "sessionId": "ec9-4e07-881d-3e9",
    "placement": "category",
    "catalogId": "628dbe95-2ec9-4e07-881d-3e9f92ab2e0b",
    "productFilters": [
         ["category:Cupboard/Snacks"]
    ],
    "options": {
                             "filterMode": "AndOr"
                             },
    "maxNumberOfAds": 3
}
```

## Errori della richiesta

### Client non valido

Se il `client_id` or `client_secret` inviato nella richiesta non è corretto, riceverai una risposta come questa:

```json
{
  "error": "invalid_client"
}
```

Assicurati di utilizzare le credenziali corrette. Controlla attentamente il tuo `client_id` e `client_secret` e assicurati di utilizzare correttamente l'autorizzazione Basic quando chiami l'endpoint /token. ##Richiesta non valida Un errore di richiesta non valida verrà restituito dall'Authorization Server se nella richiesta manca un parametro obbligatorio, se include un valore di parametro non valido, se include un parametro più di una volta o se è altrimenti conformata in modo errato.

```json
{
  "error": "invalid_request"
}
```

Assicurati di:

* Includere solo `grant_type=client_credentials` nel corpo della richiesta
* Impostare la corretta `Content-Type` nell'intestazione della richiesta


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.citrusad.com/retail-media-interface/integration/it/data-api/api-overview/oauth-20-authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
