# `PhoenixKit.Modules.Emails.BrevoOnDemandSync`
[🔗](https://github.com/BeamLabEU/phoenix_kit_emails/blob/0.4.2/lib/phoenix_kit/modules/emails/brevo_on_demand_sync.ex#L1)

On-demand, targeted Brevo event fetch for a single email log — the
Brevo-aware branch of the "sync status now" button (Details page and
the emails list row menu both call it). Unlike `BrevoPollingJob`'s
broad polling cycle, this queries Brevo's events API filtered to
exactly one `messageId` — the cheapest, most precise request the API
supports.

A manual, explicit user request: bypasses `brevo_events_enabled` (the
background poller can be off entirely and this still works) and the
per-integration opt-out list (excluding an account from the
*background* poll doesn't mean "never fetch its data even when asked
directly"). Does NOT bypass `Emails.enabled?/0` — the whole email
system being off is a stronger signal than either of those.

There's no per-log integration reference to resolve credentials from
(a `Log` doesn't record which `SendProfile`/integration sent it), so
this tries every currently *active* Brevo integration — same set
`BrevoPollingJob` polls — and aggregates whatever comes back. In the
common single-account case that's one request; `messageId` is
selective enough that a wrong account simply returns no events, not
wrong data.

# `sync`

```elixir
@spec sync(PhoenixKit.Modules.Emails.Log.t()) ::
  {:ok, %{events_processed: non_neg_integer()}} | {:error, String.t()}
```

Fetches and processes events for a single Brevo-sent log right now.

## Returns

- `{:ok, %{events_processed: n}}` — `n` may be `0` ("no new events")
- `{:error, reason}` — a user-facing string, never includes credentials

---

*Consult [api-reference.md](api-reference.md) for complete listing*
