Skip to main content

The REST API

What you can do with the API, the rules every request follows, and where the full reference lives.

The tweak.email API lets your own systems do what the app does: manage contacts, build and send campaigns, read reports, send transactional e-mail and use the AI tools. It is included in every paid plan: Starter, Pro and Business.

  • API overview: a quick start and the main concepts.
  • Full API reference: every endpoint, field and response.
  • The same reference as an OpenAPI document, for generating a client, is at /api/v1/openapi.json.

The basics

  • Base URL: https://tweak.email/api/v1
  • Authentication: an API key in the Authorization: Bearer or X-Api-Key header.
  • Format: JSON in, JSON out. Responses put the record or list under data. A create answers 201; an upsert answers 201 when it created the record and 200 when it updated one.

Rules worth knowing

  • Contacts are upserted by e-mail address. Re-sending the same contact updates it rather than creating a duplicate. A contact who unsubscribed stays unsubscribed, whatever you send.
  • Contact metadata is merged. On POST /contacts, POST /contacts/bulk and PATCH /contacts/{id}, the keys you send overwrite the stored ones, a key sent as null is removed (so is one sent as an empty string), and keys you leave out stay as they are. Send "metadata": null to clear it all.
  • Deleted contacts are gone. A deleted contact no longer appears in any list or lookup, and deleting it again returns 404. Adding the same address again brings the contact back with the data you send; if it had unsubscribed or bounced, it keeps that status.
  • Consent is required for new contacts. A request that creates a contact (or brings back a deleted one) needs consent_attested: true, confirming the person agreed to hear from you and was not taken from a bought or scraped list. Updating a contact you already have does not need it, so a sync that only changes metadata can leave it out. In POST /contacts/bulk, send it once for the whole batch or on each row that creates a contact; a batch that would create a contact without it is refused, naming each such row.
  • Tags by name or by id. Contacts take tags as tag_ids or as tags (names). A name your team has no tag for yet creates that tag. POST /contacts/{id}/tags takes either, and DELETE /contacts/{id}/tags/{tag} takes a tag id or a tag name.
  • Custom fields are defined before they are used. Values you send in metadata are stored as they are, but a segment rule on a custom field (custom.plan_tier) needs the field defined, with its type: in Settings → Contact Fields, or with POST /contact-fields. GET /contact-fields lists them. Only a field's name can be changed afterwards; deleting a field keeps the values stored on contacts.
  • Values for your contact fields are checked. When a metadata key is one of your contact fields, its value is stored in the field's type: "1200" becomes the number 1200, "yes" becomes true, a date must be written as 2026-11-15 (or as a full ISO 8601 date-time such as 2026-11-15T09:30:00Z, stored as its date). A value that cannot be converted, such as "ja" for a yes/no field, true for a number field, or 15/11/2026 or 2027-02-31 for a date field, is refused with 422 naming the key (metadata.beta_user) and the type it needs. Other keys are stored as you send them.
  • Fields an endpoint does not take are refused. Every write (POST, PUT, PATCH and DELETE) answers 422 Unsupported field: … naming each body field the endpoint does not take, such as a misspelt fist_name or a team_id, rather than ignoring it. A sequence's status cannot be set through the API either: sequences are activated in the app, after their checks. The API reference lists the fields each endpoint takes. Until 24 November 2026 most endpoints ignored such fields, so if an older integration sends extra fields, remove them.
  • Sends follow the same rules as the app: verified sending address, unsubscribe link, plan allowance, screening, and the first-send review. A refused send returns a blockers list. POST /campaigns/{id}/preflight runs the checks without sending.
  • Segment definitions are checked. A filter key the API does not know is refused with 422 naming the key, so a typo cannot quietly widen an audience to everyone. The same goes for the rules tree, which holds conditions on built-in and custom fields, all / any groups and exclusions: an unknown field, an operator the field's type does not have, a value of the wrong type, or a tag or segment id that is not your team's is refused. GET /segments/fields lists the fields and operators you can use. The filters go inside definition: a field the endpoint does not take, such as rules sent next to definition instead of inside it, is refused with 422, and POST /segments/preview without definition is refused rather than counting everyone.
  • Rule dates use your timezone. "In the last 14 days" starts at midnight in the rule tree's timezone. When you leave it out, the API saves the timezone from the team owner's profile (Settings → Profile), much as the app uses the timezone of whoever builds the rule; without one, UTC.
  • Pagination uses cursors. Pass next_cursor back as ?cursor= until has_more is false. A cursor that was changed, or that came from a different listing, is refused with 422 rather than starting again at the first page.
  • Idempotency. Send an Idempotency-Key header on writes, especially sends; for 24 hours, a retry with the same key returns the first response instead of acting twice, marked with Idempotency-Replayed: true. That includes the one-time secret of a new API key or webhook, so a retry after a lost response gets the same key back rather than a second one. Using the same key with a different request body returns 422. Keys are shared by your whole team and bound to the API key that first used them: another of your keys sending the same Idempotency-Key gets the same 422, even with an identical body, so give each integration its own keys. Retrying while the first request is still running returns 409.
  • Rate limits are counted per key and depend on your plan: 120 requests a minute on Starter, 300 on Pro and 600 on Business. Settings → API shows your plan's limit. Every response carries X-RateLimit-Limit and X-RateLimit-Remaining; a 429 response includes Retry-After and the code rate_limit_exceeded. Separately, failed authentications are limited: a key that keeps failing from one address, or an address that tries many different wrong keys in a minute, gets 429 with the code too_many_failed_auth_attempts for the rest of that minute. Keys that work from that address keep working, so one worker with an old key does not block the others.

Transactional e-mail

POST /send answers with status: "queued" and a message_id once the message has been accepted for delivery. That is not yet delivery: the email.delivered, email.bounced and email.complained webhooks for the message, and its events in GET /events, carry the same message_id. An open may be reported without it.

Add your own reference data in metadata, for example {"order_id": "4417"}: up to 20 text values. It comes back with the message's delivery webhooks and is never put in the e-mail. A field /send does not support, such as tags, headers or cc, is refused with 422 naming it rather than ignored.

The response still includes delivered: true for older integrations. It means the same as accepted (the message was accepted for delivery), is deprecated, and will be removed in a later version.

Delivery events and your own backend

POST /events is for mail you send outside tweak.email: report its delivery events (such as delivered, bounced, opened, clicked or unsubscribed) and they count in your reports and suppressions like any other. It accepts only those delivery event types, not events of your own such as "signed up" or "upgraded".

To act on something that happens in your own product, tag the contact instead: POST /contacts/{id}/tags adds a tag, and a sequence with the When tag is added trigger starts for that contact, exactly as when you add the tag in the app.

To report a purchase, a booking or a sign-up an e-mail led to, use POST /conversions with the person's address and, if you like, the value, the currency, your order number and the campaign it belongs to. An order number is only counted once. Campaign reports explains which campaign gets the credit.

Errors

Every error response has a code your program can check and a message to show, for example {"code": "missing_scope", "message": "This API key is missing a required scope.", ...}. Validation errors add errors, with the messages for each field. Responses that had an error field still have it, with the same text as message. The API reference lists the codes.

Status Meaning
400 The body was sent as JSON but is not valid JSON, or not a JSON object (invalid_json)
401 Missing, invalid, revoked or expired key (api_key_required, invalid_api_key, api_key_revoked, api_key_expired)
403 The key lacks the scope (missing_scope), or the plan does not include API access (plan_required)
404 No such record in your team (not_found)
409 A request with the same Idempotency-Key is still running; retry shortly
422 Validation failed (validation_failed), or a send check failed
429 Too many requests; wait and retry (rate_limit_exceeded, too_many_failed_auth_attempts)
502 A transactional message could not be handed over for delivery; nothing was sent, retry shortly (send_failed)
503 Sending (or the AI tools) is temporarily unavailable; retry later

When the plan does not include the API

If your team's plan has no API access, for example after a free trial ends, every endpoint except GET /me answers 403 with the code plan_required, the plan you need in required_plan and, after a trial, the date it ended in trial_ended_at. GET /me keeps working and shows api_access: false. Your keys, webhook endpoints and settings are kept, and everything works again as soon as the team is on a paid plan.

Before your first API send

Until your team's first send has been reviewed, transactional and test e-mails sent through the API can only go to members of your team. Blocked calls return 403 with review_pending: true.

The same applies until a team owner or admin has accepted the Data Processing Agreement in the app: transactional e-mails to anyone but your team members return 403 with dpa_required: true, and campaign sends and schedules are refused with the DPA listed among their blockers.

To be told about events instead of asking for them, use webhooks.