Skip to content

API

Unsubscribing from your application

Unsubscribe a contact from your server, or offer a preferences page in your application that uses the signed token of the unsubscribe link; customize the default preferences page.

Voaaro already handles unsubscribing for every broadcast: a footer with the link, the one-click List-Unsubscribe header and a hosted preferences page. This page shows how to do it on your side: from your server, or from a page of your application.

From your server

Same key as for subscribing: the domain's application key, sending_access allowed.

Node / Bun

const { data } = await voaaro.newsletter.unsubscribe({ email: "ada@example.org" })

Python

r = voaaro.Newsletter.unsubscribe({"email": "ada@example.org"})

PHP

$r = $voaaro->newsletter->unsubscribe(['email' => 'ada@example.org']);

Go

sub, err := client.Newsletter.Unsubscribe(&voaaro.UnsubscribeRequest{Email: "ada@example.org"})

cURL

curl https://mail.example.com/api/v1/newsletter/unsubscribe \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{"email": "ada@example.org"}'
JSON
{
  "object": "subscription",
  "email": "ada@example.org",
  "contact_id": "7c1d9e42-0a3b-4f6e-8d21-5b9f0c3e7a14",
  "status": "unsubscribed",
  "topics": [{ "id": "7a1c…", "name": "News", "subscription": "opt_in" }]
}
  • email or contact_id: required; unknown address: 404. domain if the key covers several domains.
  • Without topic_ids: unsubscribes from every broadcast of the domain; messages already queued for this contact are canceled. Produces the contact.unsubscribed webhook (source: "api").
  • With topic_ids: only these topics switch to opt_out; the contact stays subscribed to other broadcasts (status: "subscribed"), with no contact.unsubscribed.
  • The change is written to the audit log (contact.unsubscribe, actor apikey:<id>). Idempotency-Key is accepted.
  • An address's state is read with GET /newsletter/subscriptions/{email}. To resubscribe from your server, call POST /newsletter/subscribe again: it is an explicit request.

Your application can have its own "Manage my emails" page. It calls the form's public routes, with its public key and the same allowed origins.

Why a token, not the address

If an address were enough, anyone could unsubscribe anyone. The public routes therefore require the signed token of the unsubscribe link, which only the message's recipient has. Put it in your broadcast's link with the {{{VOAARO_UNSUBSCRIBE_TOKEN}}} variable (or {{ unsubscribe_token }}):

HTML
<a href="https://app.example.com/unsubscribe?token={{{VOAARO_UNSUBSCRIBE_TOKEN}}}">Manage my emails</a>

Your page reads token from its address and passes it to the routes below. A token from another domain than the form's responds 404 invalid_token.

MethodPath (/api/v1/newsletter/public/{public_key}/…)BodyResponse
GETpreferences?token=…preferences
POSTunsubscribetoken, topic_ids (optional)preferences
POSTresubscribetokenpreferences
JSON
{
  "object": "preferences",
  "test": false,
  "email": "a***@example.org",
  "unsubscribed": false,
  "topics": [{ "id": "7a1c…", "name": "News", "description": "Once a month", "subscribed": true }]
}
  • email is masked: the page does not reveal the full address to whoever finds the link.
  • topics: the domain's public topics, checked or not for this contact.
  • unsubscribe without topic_ids unsubscribes from everything (contact.unsubscribed webhook, source: "public_api"); with them, from these topics only. resubscribe undoes an unsubscribe.
  • A test send token gives test: true and changes nothing.
  • GET never changes anything: antivirus scanners and link previews that open addresses unsubscribe nobody.
HTML
<p id="prefs">Loading…</p>
<button id="stop">Unsubscribe me from everything</button>

<script type="module">
  const API = "https://mail.example.com/api/v1/newsletter/public/mlk_pub_0123456789abcdef0123456789abcdef"
  const token = new URLSearchParams(location.search).get("token")
  const show = (p) => (document.getElementById("prefs").textContent = p.unsubscribed ? `${p.email}: unsubscribed.` : `${p.email}: subscribed.`)

  fetch(`${API}/preferences?token=${encodeURIComponent(token)}`).then((r) => r.json()).then(show)
  document.getElementById("stop").addEventListener("click", async () => {
    const r = await fetch(`${API}/unsubscribe`, { method: "POST", headers: { "Content-Type": "text/plain" }, body: JSON.stringify({ token }) })
    show(await r.json())
  })
</script>

The SDKs have the same calls: PublicForm with getPreferences(token), unsubscribe(token, { topicIds }), resubscribe(token) (Node; get_preferences, unsubscribe, resubscribe in Python, same names in PHP and Go).

Default preferences page

The page hosted by Voaaro ({{{unsubscribe_url}}}, {{ preferences_url }} link) is customized per domain, in the console (Newsletters › Newsletter settings, "Unsubscribe and preferences page") or with PATCH /api/v1/newsletter/settings and preferences_page:

FieldRule
title150 characters
intro1,000 characters; {email} inserts the masked address
done_message500 characters, shown after unsubscribing
languagefr, en, es, it, ru, zh-CN, de; absent: the browser's language
accent_color, background_color#rrggbb
image_urlas for a form: https:// or embedded image, never SVG
cURL
curl -X PATCH https://mail.example.com/api/v1/newsletter/settings \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{"preferences_page": {"title": "Your Acme emails", "intro": "Choose what {email} receives.", "accent_color": "#d9480f"}}'

The object replaces the previous one; {} or null restores the original page (texts translated in seven languages). It is read back in GET /api/v1/newsletter/settings. The behavior does not change: a GET changes nothing, List-Unsubscribe works in one click.

POST /api/v1/newsletter/preferences-page/preview with { preferences_page?, page: "form" | "done" } renders the page without saving anything, for a sample contact and the domain's public topics: { object: "preferences_page_preview", html }.

Esc