Primitive
Docs menuEndpoints, Filters & Deliveries
Concepts

Endpoints, Filters & Deliveries

Manage webhook endpoints and their delivery rules, set allow/block sender filters, and inspect or replay past webhook deliveries.

This page covers the three controls that decide where inbound mail is delivered and what reaches each destination:

  • Endpoints — the HTTP URLs and Primitive Functions that receive your mail, plus the per-endpoint rules that filter what they get.
  • Filters — org-wide or per-domain allow/block lists keyed on the sender address.
  • Webhook deliveries — the delivery history you can list, inspect, and replay.

This is distinct from Custom Routes: a route binds a recipient address pattern to a single destination, while this page manages the destinations themselves and the rules that govern delivery to them. For the end-to-end inbound flow, see Receiving Mail.

All endpoints below live under https://api.primitive.dev/v1 and authenticate with a bearer API key.

Endpoints

An endpoint is a delivery destination for inbound mail. It comes in two kinds:

  • kind: "http" — a webhook url you host. It must be HTTPS and publicly reachable; private and loopback hosts are rejected.
  • kind: "function" — a hosted Primitive Function, referenced by function_id. No URL is sent over the wire; Primitive dispatches to the function internally.

Create an endpoint

Create an HTTP endpoint:

bash
curl -X POST https://api.primitive.dev/v1/endpoints \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "http",
    "url": "https://api.acme.dev/hooks/primitive",
    "enabled": true
  }'

Create a function-backed endpoint instead by passing function_id and omitting url:

bash
curl -X POST https://api.primitive.dev/v1/endpoints \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "function",
    "function_id": "<function-uuid>"
  }'

kind defaults to "http". For an HTTP endpoint, url is required and function_id is not allowed; for a function endpoint, function_id is required and url is not allowed. enabled defaults to true. Pass domain_id to scope the endpoint to one of your organization's domains (see the active-endpoint rule below). A function has at most one endpoint — recreating it returns the existing row.

The one-active-endpoint-per-domain rule

Each domain has a single default destination slot. An organization also has one org-wide fallback slot (the endpoint with domain_id: null), used for domains that have no scoped endpoint of their own.

  • Only one active, default-destination endpoint may occupy a given domain's slot (or the org-wide fallback slot). Creating or re-enabling a second one returns 409 conflict; delete the existing endpoint first.
  • Endpoints created with is_route_target: true are exempt from this slot. They are reachable only through an explicit route and never serve as a domain default, so many of them can share a domain. Routes mint these for you when you point a route at a function_id.

Plan limits apply to the default slots: the free Developer plan allows a single global (org-wide) webhook, and per-domain endpoints require a paid plan. Your effective webhooks_max_global and webhooks_per_domain limits are reported by Limits.

List, update, and delete

bash
# list active endpoints
curl https://api.primitive.dev/v1/endpoints \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"

# change the URL, scope, rules, or enabled flag
curl -X PATCH https://api.primitive.dev/v1/endpoints/<endpoint-uuid> \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "enabled": false }'

# remove an endpoint
curl -X DELETE https://api.primitive.dev/v1/endpoints/<endpoint-uuid> \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"

PATCH accepts url, enabled, domain_id, and rules. You cannot set url on a function endpoint. Deleting an endpoint deactivates it; deactivated endpoints stop receiving mail and free up their domain slot.

The rules object

Every endpoint carries a rules object that filters which messages it receives. All fields are optional and ANDed together — a message must pass every rule present to be delivered. An empty object ({}, the default) applies no filtering.

FieldTypeMeaning
max_size_bytesintegerMaximum total email size in bytes. Larger messages are not delivered to this endpoint.
exclude_attachmentsbooleanWhen true, deliver only messages that have no attachments.
attachment_limit_mbnumberMaximum total attachment size in MB. Larger messages are skipped.
sender_whitelistarray of emailsWhen set, deliver only from these sender addresses.
sender_blacklistarray of emailsWhen set, never deliver from these sender addresses.
event_typesarray of stringsEvent types this endpoint subscribes to (1 to 50 entries). Omitted = receive every event type except the opt-in sent_email.* events, which an endpoint receives only if it lists them. An empty array is rejected; omit the field instead.

The size and attachment rules (max_size_bytes, attachment_limit_mb, exclude_attachments) are evaluated against a fast approximation of the message size, not an exact byte count, so treat their thresholds as approximate.

Set rules at create time or with PATCH:

bash
curl -X PATCH https://api.primitive.dev/v1/endpoints/<endpoint-uuid> \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "rules": {
      "max_size_bytes": 5242880,
      "exclude_attachments": true,
      "sender_whitelist": ["alerts@acme.dev"],
      "event_types": ["email.received"]
    }
  }'

How event_types controls subscription

event_types decides which event types reach the endpoint. If you omit it, the endpoint receives every event type except the opt-in sent_email.* events. This is the default and the grandfathered behavior for endpoints that predate event subscriptions. If you set it, the endpoint receives only the listed types (for example email.received, email.bounced) and nothing else. See Webhook Payload for the full list of event types and their field semantics.

sent_email.accepted, sent_email.delivered, sent_email.failed and sent_email.completed (events about mail you send, see Sent Email Events) are delivered only to an endpoint that lists them, and only for sends made after the endpoint first listed one of them. They carry a different payload from inbound mail, so we recommend a dedicated endpoint; an endpoint that also handles inbound mail must keep its inbound event types in the list. Route-target endpoints, pull endpoints and Function endpoints do not receive them, and a domain-scoped endpoint receives them only for sends from its domain.

Subscriptions are matched by exact string, and values are not validated against the known event names. A typo like email.bouncd saves without error and silently matches nothing, so the endpoint quietly receives no events of that kind. Copy event names verbatim from Webhook Payload. A test send only validates email.received; verify specialized subscriptions such as email.bounced with a real matching event or by checking webhook deliveries.

The other rules fields filter on message content (size, attachments, sender); event_types filters on the event itself. They compose: an endpoint can subscribe to only email.received and require the message be under 5 MB and come from a whitelisted sender.

Test an endpoint

Send a synthetic email.received payload to an HTTP endpoint to confirm it is reachable and that your signature verification works:

bash
curl -X POST https://api.primitive.dev/v1/endpoints/<endpoint-uuid>/test \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"

The response reports the HTTP status your endpoint returned, a truncated body, and the signature that was sent. The test payload is signed exactly like a real delivery, so use it to validate your signature verification. Testing applies to HTTP endpoints only — there is nothing to call for a function-backed endpoint.

Because the test always sends an email.received payload, it confirms reachability and signing but cannot validate a specialized event_types subscription (such as email.bounced).

Test sends are rate limited to 4 per minute and 30 per hour per organization. Successful tests, and tests against a URL on one of your verified domains, do not count against the per-minute limit.

Filters

Filters are allow/block lists evaluated on the sender address, applied in addition to any per-endpoint sender_whitelist / sender_blacklist rules. A filter has a type and a pattern:

  • type: "whitelist": matches the From address. A matching sender skips the blocklist and the spam threshold only when that From authenticates: DMARC-aligned SPF or DKIM, or, for a domain with no DMARC evaluation, a signature the sending provider attests for that domain. A message that got past a blocklist or the spam threshold only because of the whitelist, and then fails authentication, is not delivered and shows as rejected (sender_blocked). Mail sent through an email service provider matches on its From address, not its bounce address.
  • type: "blocklist": matches the envelope sender (SMTP MAIL FROM) or the From address, and rejects the message.

When a blocklist rule and a whitelist rule both match, the more specific rule wins. An exact address (user@example.com) is more specific than a whole domain (*@example.com or example.com), which is more specific than a wildcard domain (*.example.com), which is more specific than *. So a blocklist entry for user@example.com still rejects that address even when example.com is whitelisted. When both rules are equally specific, the whitelist rule applies.

For allowlist-only mode, add whitelist rules for your trusted senders and a * blocklist rule to reject everyone else.

bash
# block a specific sender org-wide
curl -X POST https://api.primitive.dev/v1/filters \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "type": "blocklist", "pattern": "spam@bad.example" }'

Patterns are normalized to lowercase and trimmed before storage, and may be up to 500 characters. New filters are created enabled.

Per-domain scoping

Pass domain_id to scope a filter to a single one of your organization's domains instead of the whole organization:

bash
curl -X POST https://api.primitive.dev/v1/filters \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "whitelist",
    "pattern": "partner@acme.dev",
    "domain_id": "<domain-uuid>"
  }'

Per-domain filters require a paid plan; org-wide filters (domain_id omitted or null) are available on all plans.

List, toggle, and delete

bash
# list filters, newest first
curl https://api.primitive.dev/v1/filters \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"

# enable or disable a filter (the only patchable field)
curl -X PATCH https://api.primitive.dev/v1/filters/<filter-uuid> \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "enabled": false }'

# remove a filter
curl -X DELETE https://api.primitive.dev/v1/filters/<filter-uuid> \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"

PATCH only toggles enabled. To change a pattern or type, delete the filter and create a new one.

Webhook deliveries

Every attempt to deliver an event to an endpoint (an inbound email, or an opt-in sent_email.* event) is recorded as a delivery. The delivery history is your audit trail for what fired, when, and whether it succeeded.

List deliveries

bash
curl "https://api.primitive.dev/v1/webhooks/deliveries?limit=50&status=failed" \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"

Supported query parameters:

ParameterMeaning
limitPage size, 1–100 (default 50).
cursorOpaque cursor from the previous page's meta.cursor, for pagination.
email_idOnly deliveries for this inbound email.
event_typeOnly deliveries of this event type, for example sent_email.failed.
sent_email_idOnly deliveries of sent_email.* events about this sent email.
statusOne of pending, delivered, header_confirmed, failed, skipped_by_rules.
date_from / date_toISO 8601 timestamps bounding created_at.

Results are newest-first. The response meta includes total and a cursor for the next page (null when there are no more).

Inspect a delivery

bash
curl https://api.primitive.dev/v1/webhooks/deliveries/<delivery-id> \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"
json
{
  "id": "184293",
  "org_id": "7f2c1d84-0a5b-4c96-8e37-2b6d9f01c4a8",
  "email_id": "a0d6f29c-4e13-4b87-9c52-1f8a3e7b6d09",
  "event_type": "email.received",
  "sent_email_id": null,
  "endpoint_id": "c4a9e1b7-3d28-4f60-b915-8e2c7a0d6f31",
  "endpoint_url": "https://api.acme.dev/hooks/primitive",
  "status": "failed",
  "attempt_count": 3,
  "duration_ms": 812,
  "last_error": "HTTP 500: internal error",
  "last_error_code": "handler_5xx",
  "created_at": "2026-06-26T14:03:11.000Z",
  "updated_at": "2026-06-26T14:08:42.000Z",
  "email": {
    "sender": "alerts@acme.dev",
    "recipient": "ops@yourdomain.com",
    "subject": "Disk usage warning"
  }
}

status is delivered (2xx), header_confirmed (2xx plus a confirmation header from your handler), failed, or pending. last_error and last_error_code explain failures. event_type is the delivered event type (null for deliveries recorded before event types existed). A sent_email.* delivery has email_id and email set to null and sent_email_id set to the send it is about. For a function-backed endpoint, endpoint_url is an opaque function://<id> identifier rather than a callable URL.

For a webhook URL, an HTTP failure records the error.code from a Primitive API error envelope when your handler returns one, and otherwise handler_4xx or handler_5xx. The exact status is in last_error (for example HTTP 500: internal error).

Deliveries to a function-backed endpoint can carry these last_error_code values in addition to the ordinary HTTP failure codes:

  • function_timeout: the invocation exceeded the 10-minute wall-clock window and was canceled. The delivery is retried on the standard schedule. See Functions for how the wall-clock and CPU limits relate.
  • content_discarded: the stored email content was discarded before the delivery could complete, so there was nothing left to deliver.
  • superseded: another delivery to the same endpoint already succeeded for this email, so this one was skipped rather than delivered twice.
  • queue_dead_letter: the dispatch could not be completed after repeated attempts. Replay the delivery to try again.

Replay a delivery

After fixing a handler, re-send the stored payload to the endpoint:

bash
curl -X POST https://api.primitive.dev/v1/webhooks/deliveries/<delivery-id>/replay \
  -H "Authorization: Bearer $PRIMITIVE_API_KEY"
json
{ "delivered": 1, "failed": 0 }

Replay of an inbound email delivery reuses the original stored payload and event id, so your handler's idempotency rules still apply: the same email is not re-ingested. Replay re-sends to the original endpoint; if it has been deleted or deactivated (delete is a soft-deactivate), the replay is rejected. Note that merely disabling an endpoint (enabled: false) does not block replay: the original still receives it. Replay supports inbound email deliveries and sent_email.* deliveries, and is rate limited per organization. A sent_email.* delivery is replayed with the same event id but a payload rebuilt from the send as it is now; it is rejected if the send was deleted or the endpoint is no longer an active http endpoint.

To re-deliver a whole inbound email (rather than one delivery row), see the replay flow in Receiving Mail.