Skip to content

API

Your own signup form

Subscribe your application's visitors to the newsletter, from your server (application key) or straight from the browser (public form key), with double opt-in, anti-bot protection and an editable default signup page.

You already have a site or an application with its own "Get the newsletter" form? Connect it to Voaaro in one of two ways:

From your serverFrom the browser
Keythe domain's application key (mlk_…), secreta form's public key (mlk_pub_…), visible in the page
PathPOST /api/v1/newsletter/subscribePOST /api/v1/newsletter/public/{public_key}/subscribe
Anti-botup to you (your server decides)honeypot, proof of work, per-IP limits, allowed origins
Responsedetailed (contact_id, state)the same for every address

Either way, the signup follows the settings of the domain's default form (or of a chosen form): double opt-in, segments to file the subscriber in, language and look of the confirmation email. Prefer a ready-made page? The default form has its own hosted page, editable in the console.

From your server

Your application's server calls Voaaro with an application key covering the domain. A sending_access key is enough: the application that already sends its emails can also subscribe its users. A personal key gets 401 restricted_api_key. If the key covers several domains, give domain (in the body or ?domain=); a domain outside the key responds 404.

Node / Bun

const { data, error } = await voaaro.newsletter.subscribe({
  email: "ada@example.org",
  firstName: "Ada",
  topicIds: ["7a1c…"],
  consent: { text: "I agree to receive the Acme newsletter.", ip: req.ip, userAgent: req.get("user-agent") },
})
if (data?.status === "pending") console.log("confirmation email sent")

Python

r = voaaro.Newsletter.subscribe({
    "email": "ada@example.org",
    "first_name": "Ada",
    "topic_ids": ["7a1c…"],
    "consent": {"text": "I agree to receive the Acme newsletter.", "ip": request.remote_addr, "user_agent": request.user_agent.string},
})

PHP

$r = $voaaro->newsletter->subscribe([
    'email' => 'ada@example.org',
    'firstName' => 'Ada',
    'topicIds' => ['7a1c…'],
    'consent' => ['text' => 'I agree to receive the Acme newsletter.', 'ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? ''],
]);

Go

sub, err := client.Newsletter.Subscribe(&voaaro.SubscribeRequest{
	Email:     "ada@example.org",
	FirstName: "Ada",
	TopicIds:  []string{"7a1c…"},
	Consent:   &voaaro.SubscriptionConsent{Text: "I agree to receive the Acme newsletter.", Ip: r.RemoteAddr, UserAgent: r.UserAgent()},
})

cURL

curl https://mail.example.com/api/v1/newsletter/subscribe \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "email": "ada@example.org",
    "first_name": "Ada",
    "topic_ids": ["7a1c…"],
    "consent": {"text": "I agree to receive the Acme newsletter.", "ip": "203.0.113.7", "user_agent": "Mozilla/5.0 …"}
  }'
JSON
{
  "object": "subscription",
  "email": "ada@example.org",
  "status": "pending",
  "contact_id": null,
  "form_id": "2b8f4e10-6c3d-4a97-b5e2-19d7c0a4f863",
  "double_opt_in": true
}
FieldRule
emailrequired
first_name, last_name100 characters at most
propertiesvalues of declared properties: { "key": value }
segment_ids (or segments)segments to file the subscriber in, on top of the form's
topics or topic_idstopics: [{ "id", "subscription": "opt_in" | "opt_out" }], or a list of ids (subscribed)
form_idform whose settings to follow (active, on the domain; disabled: 409); the default form otherwise
double_opt_inoverrides the form's choice
consent{ text, ip, user_agent }, kept on the signup then on the contact, with the key id; default text: the form's
domainwhen the key covers several domains
  • Double opt-in (default): the response says "status": "pending" and the confirmation email goes out, from the sender in the settings (no sender: 422, message double_opt_in : …). The contact only exists after the link is clicked; contact_id is then null.
  • Without double opt-in: "status": "subscribed", the contact is created (or resubscribed) right away.
  • Idempotent: an address already subscribed stays subscribed, with no new email; the given fields are updated, segments and topics added. An address gets at most one confirmation email per 24 hours across all the domain's forms (3 at most across the whole instance); beyond that, the response stays pending, with no email. Topics not mentioned do not change: the API never unchecks anything.
  • Idempotency-Key is accepted, as on the other POST routes (idempotency).

Reading an address's state

GET /api/v1/newsletter/subscriptions/{email} tells where an address stands on the domain, for instance to show "You are subscribed" in the user's account:

JSON
{
  "object": "subscription",
  "email": "ada@example.org",
  "status": "subscribed",
  "contact_id": "7c1d9e42-0a3b-4f6e-8d21-5b9f0c3e7a14",
  "created_at": "2026-11-12T10:21:44Z",
  "unsubscribed_at": null,
  "source": "api",
  "pending": null,
  "topics": [{ "id": "7a1c…", "name": "News", "subscription": "opt_in" }],
  "segments": [{ "id": "…", "name": "Website" }]
}

status: subscribed, unsubscribed, pending (signup not confirmed yet: pending gives form_id and created_at) or none (unknown address). To unsubscribe, see Unsubscribing from your application.

Without a server (static site, landing page), the browser calls Voaaro directly with a form's public key: mlk_pub_ followed by 32 hexadecimal characters. It is not a secret: it only allows subscribing to that form and managing preferences with an unsubscribe link. Read it in the console (the form, "Your application" tab) or in public_key from GET /api/v1/forms/{id}. POST /api/v1/forms/{id}/rotate-key changes it: the old one stops working at once.

MethodPath (/api/v1/newsletter/public/{public_key}/…)BodyResponse
POSTchallenge{ object: "challenge", challenge, bits }
POSTsubscribeemail, first_name, last_name, properties, topic_ids, consent, website, challenge, nonce{ object: "subscription", status: "pending" | "subscribed" }
OPTIONSall204, CORS preflight
  • properties: only the form's fields; a missing required field responds 422.
  • topic_ids: among the topics the form offers.
  • consent: true if the form has a consent text (the box must be ticked, 422 otherwise); the text kept is the form's, with the IP address and the browser.

Allowed origins (CORS)

Declare your pages' addresses on the form, field allowed_origins (10 at most, https://host[:port]; http://localhost is allowed for testing):

cURL
curl -X PATCH https://mail.example.com/api/v1/forms/$FORM_ID \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{"allowed_origins": ["https://www.example.com", "http://localhost:5173"]}'

The Access-Control-Allow-Origin header is only returned to these origins; any other gets 403 origin_not_allowed. A request without an Origin header (a server call) goes through: CORS only protects browsers. The body is read as JSON whatever its Content-Type: send it as text/plain to avoid the OPTIONS preflight.

Anti-bot protection

  • Honeypot: a hidden website field, left empty by humans. When filled, the response is the same but nothing is kept.
  • Proof of work (require_challenge, true by default): before each signup, ask for a challenge (POST …/challenge), then find a nonce (a number written in decimal digits, 24 digits at most) such that SHA-256("<challenge>:<nonce>") starts with at least bits zero bits. A challenge works once and expires; missing, wrong or already used: 400 challenge_required. It takes a browser a fraction of a second, but is expensive for anyone trying to subscribe thousands of addresses. The SDKs provide solveChallenge.
  • Limits: 20 signups per hour per IP address, and the per-IP limit on public requests (limits): 429 beyond.
  • No enumeration: for a valid address, the response is the same whether it is new, already subscribed, unsubscribed or pending (pending with double opt-in, subscribed otherwise). Nobody can use your form to test whether an address is subscribed.

Double opt-in remains the real protection of your lists: an address typed in by a third party only gets a confirmation email, with no follow-up unless it clicks.

Complete example

An HTML form and about thirty lines of JavaScript, no library:

HTML
<form id="newsletter">
  <input type="email" name="email" required placeholder="you@example.org" autocomplete="email">
  <input type="text" name="first_name" placeholder="First name" autocomplete="given-name">
  <!-- Honeypot: invisible, left empty by humans. -->
  <input type="text" name="website" tabindex="-1" autocomplete="off" aria-hidden="true"
         style="position:absolute;left:-10000px">
  <button>Subscribe</button>
  <p id="newsletter-message" role="status"></p>
</form>

<script type="module">
  const API = "https://mail.example.com/api/v1/newsletter/public/mlk_pub_0123456789abcdef0123456789abcdef"

  // POST as text/plain: no CORS preflight.
  async function post(path, body = {}) {
    const r = await fetch(`${API}/${path}`, { method: "POST", headers: { "Content-Type": "text/plain" }, body: JSON.stringify(body) })
    const data = await r.json()
    if (!r.ok) throw new Error(data.message)
    return data
  }

  // Proof of work: SHA-256("<challenge>:<nonce>") must start with `bits` zero bits.
  async function solveChallenge(challenge, bits) {
    const encoder = new TextEncoder()
    for (let nonce = 0; ; nonce++) {
      const hash = new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(`${challenge}:${nonce}`)))
      let zeros = 0
      for (const byte of hash) {
        zeros += byte === 0 ? 8 : Math.clz32(byte) - 24
        if (byte !== 0) break
      }
      if (zeros >= bits) return String(nonce)
    }
  }

  document.getElementById("newsletter").addEventListener("submit", async (event) => {
    event.preventDefault()
    const form = event.currentTarget
    const message = document.getElementById("newsletter-message")
    form.querySelector("button").disabled = true
    try {
      const { challenge, bits } = await post("challenge")
      const nonce = await solveChallenge(challenge, bits)
      const fields = Object.fromEntries(new FormData(form))
      const { status } = await post("subscribe", { ...fields, challenge, nonce })
      message.textContent = status === "pending" ? "Almost done: confirm with the link we just emailed you." : "Thanks, you are subscribed."
      form.reset()
    } catch (e) {
      message.textContent = e.message
    } finally {
      form.querySelector("button").disabled = false
    }
  })
</script>

With the Node SDK (the @deveryidea/voaaro/public subpath does not depend on Node: it works in the browser, with fetch and crypto.subtle), subscribeWithChallenge asks for the challenge, solves it and subscribes. Python (voaaro.PublicForm(key, base_url=…) or client.public_form(key)), PHP (Voaaro::publicForm(key)) and Go (voaaro.NewPublicForm(key)) have the same class, useful for tests; each also provides the proof of work alone: solveChallenge, solve_challenge, PublicForm::solveChallenge, voaaro.SolveChallenge.

Node / Bun
import { PublicForm } from "@deveryidea/voaaro/public"

const form = new PublicForm("mlk_pub_0123456789abcdef0123456789abcdef", { baseUrl: "https://mail.example.com" })
const { data, error } = await form.subscribeWithChallenge({ email: "ada@example.org", firstName: "Ada" })

The same call from a terminal (no Origin, hence no CORS check), once the challenge is solved:

cURL
curl -X POST https://mail.example.com/api/v1/newsletter/public/mlk_pub_0123…/challenge
curl https://mail.example.com/api/v1/newsletter/public/mlk_pub_0123…/subscribe \
  -H "Content-Type: application/json" \
  -d '{"email": "ada@example.org", "first_name": "Ada", "website": "", "challenge": "v1.18.…", "nonce": "48213"}'

Default signup page

Each domain has a default form: it sets the rules for API signups (without form_id), and it is also a hosted page ready to share (https://mail.example.com/n/<id>).

  • GET /api/v1/newsletter/default-form (?domain= if the key covers several domains) returns it, and creates it on first read: is_default: true, double opt-in, first name field, the instance's language.
  • It is edited like any other form, with PATCH /api/v1/forms/{id} (fields), and in the console (Newsletters › Signup forms, "Default signup page"). It cannot be deleted (409): disable it ("status": "disabled").

Presentation fields, for every form:

FieldRule
image_urlimage at the top of the page: an https:// address, or a PNG, JPEG, GIF or WebP image embedded in base64 (data:image/png;base64,…, 200 KB at most); never SVG
background_color#rrggbb, #f6f6f7 by default
accent_color#rrggbb (button, links)
allowed_origins, require_challengebrowser API (above)
is_default, public_keyread only

The page accepts no HTML from you: texts are escaped, one paragraph per blank line, colors and image checked. The confirmation email reuses the color, background and image (if it is an https:// address).

Preview

POST /api/v1/forms/{id}/preview renders the page with a draft's fields, without saving anything: { object: "form_preview", html }. page picks the screen: form (default), pending ("check your inbox"), subscribed, confirm (after the click). The console shows it in an isolated frame.

cURL
curl https://mail.example.com/api/v1/forms/$FORM_ID/preview \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{"title": "The Acme letter", "background_color": "#fff8ec", "page": "pending"}'

Webhooks

Every signup, whatever the path, produces the subscription webhooks: contact.subscribed when the contact is subscribed, contact.confirmed when a double opt-in is confirmed, with source (api from your server, public_api from the browser, form from the hosted page).

Esc