> 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/sv/data-api/api-overview/oauth-20-authentication.md).

# OAuth 2.0-autentisering

{% hint style="info" %}
OAuth 2.0 är endast tillgängligt på slutpunkten /ads

När du integrerar orderrapportering via API behöver du integrera slutpunkten /orders med Basic-autentisering och din hemliga API-nyckel.
{% endhint %}

## Client ID och Client Secret

Din `client_id` och din `client_secret` tillhandahålls av din Technical Account Manager. Din Client Secret är privat och ska inte delas.

## Begära Access Tokens

För att erhålla en Access Token måste du skicka en begäran som innehåller `client_id` och `client_secret`. För att göra det måste återförsäljaren göra en POST-begäran till Epsilon Retail Media Auktoriseringsserverns slutpunkt:

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

{% hint style="info" %}
`/oauth2/token` tillhandahåller endast den relevanta tokenen. Du kommer att använda dessa tokens för att interagera med de olika integrationsslutpunkterna.
{% endhint %}

Din begäran kräver en Basic Authorization som skickas via begäranshuvudet Authorization och innehåller återförsäljarens `client_id` och `client_secret` base64-kodad:

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

Du måste lägga till följande parameter med formatet `application/x-www-form-urlencoded` i HTTP-begärans brödtext:

`grant_type=client_credentials`

Begäran kommer att se ut så här:

```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
```

## Ta emot din Access Token

Svaret kommer att innehålla följande information

* `access_token`: Den access token som ska användas vid anrop till Epsilon Retail Media API:er
* `expires_in`: Tiden, i sekunder, tills access token går ut
* `token_type`: Typen av token som returneras. Det kommer alltid att vara Bearer i detta fall

Ett exempelsvar visas nedan

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

## Använda Token

Anrop till Epsilon Retail Media API-slutpunkter kan göras genom att helt enkelt lägga till den genererade Access Token i Authorization-huvudet i begäran `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
}
```

## Begäransfel

### Ogiltig klient

Om den `client_id` or `client_secret` som skickades i begäran är felaktig, kommer du att få ett svar som detta:

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

Se till att du använder rätt autentiseringsuppgifter. Dubbelkolla din `client_id` och `client_secret` och se till att du använder Basic Authorization korrekt när du anropar slutpunkten /token. ##Ogiltig begäran Ett fel om ogiltig begäran returneras från auktoriseringsservern om begäran saknar en obligatorisk parameter, innehåller ett ogiltigt parametervärde, innehåller en parameter mer än en gång, eller på annat sätt är felaktig.

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

Se till att:

* Endast inkludera `grant_type=client_credentials` i begärans brödtext
* Ställa in rätt `Content-Type` i begärans huvud


---

# 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/sv/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.
