# Frontend Guide: Marketing API (2026-04-03)

## Media (Images / Videos)

Media files are available via direct links and **do not require** `Authorization: Bearer ...`.

Use `imageFilename` (or `mediaFilename`) from API responses and prefix it with:

`https://api.konturai.kz/api/marketing/`

Example:

```html
<img src="https://api.konturai.kz/api/marketing/image_1772616225367_1567876836.png" />
```

## Campaign Status Polling

Endpoint:

`GET /api/marketing/targeting/campaigns/{id}/status`

Response includes `isTerminal`:

- If `isTerminal === true`, campaign status is terminal (success or error).
- Stop polling when terminal and proceed to prediction fetch.

Suggested polling loop:

```js
const poll = setInterval(async () => {
  const res = await fetch(`/api/marketing/targeting/campaigns/${id}/status`);
  const data = await res.json();
  setStatus(data.status);
  if (data.isTerminal) {
    clearInterval(poll);
    fetchPrediction();
  }
}, 3000);
```

## AI Prediction

Endpoint:

`GET /api/marketing/targeting/campaigns/{id}/prediction`

Behavior:

- `200 OK`: prediction is ready.
- `202 Accepted`: prediction is generating in background. Repeat request in ~10-15 seconds.

Optional manual trigger (if automation did not start):

`POST /api/marketing/targeting/campaigns/{id}/predict`

