MOLTED EMAIL

Inbound Webhook Mappings

Connect external services like Clerk, Stripe, and Supabase to Molted Email without writing code.

Inbound webhook mappings let you receive webhooks from external services and automatically route data into Molted features -- sync contacts, subscribe to lists, or trigger journeys. No code required.

How it works

  1. Create an inbound webhook mapping in Molted
  2. Build its webhook URL from the urlToken in the response (e.g., https://api.molted.email/v1/hooks/ink_abc123...)
  3. Paste that URL into your provider's webhook settings
  4. Configure where the email lives in the payload, field mappings, and actions

When the provider sends a webhook, Molted extracts the email address, maps fields, and executes your configured actions.

Creating a webhook mapping

Via CLI

molted inbound-hooks create \
  --name "Clerk Signups" \
  --source clerk \
  --email-path "data.email_addresses[0].email_address" \
  --field-map "name=data.first_name" \
  --field-map "clerkId=data.id" \
  --action "sync_contact" \
  --action "subscribe_to_list:lst_abc"

Append :confirm to require double opt-in on that subscription (see Double opt-in below):

  --action "subscribe_to_list:lst_abc:confirm"

To fire a journey event, use --action "trigger_journey:<eventName>" (the event name can't contain a :). --field-map key=path and --action can be repeated; --name and --email-path are required, --source is an optional label.

Via API

POST /v1/agent/inbound-hooks
{
  "name": "Clerk Signups",
  "source": "clerk",
  "emailPath": "data.email_addresses[0].email_address",
  "fieldMappings": {
    "name": "data.first_name",
    "clerkId": "data.id"
  },
  "actions": [
    { "type": "sync_contact" },
    { "type": "subscribe_to_list", "listId": "lst_abc", "requireConfirmation": true }
  ]
}

name and emailPath are required, non-empty strings (a missing or empty one, on create or update, is 400 invalid_inbound_hook naming the field). source is a free-text label with no behaviour. requireConfirmation is optional and defaults to false. Action parameters aren't checked when you save the mapping (an unknown action type, or subscribe_to_list without a listId, is accepted and fails on each delivery), so dry-run it with test first.

The response is the mapping: { id, tenantId, name, source, urlToken, emailPath, fieldMappings, actions, enabled, createdAt, updatedAt }. urlToken is ink_ followed by 48 hex characters. Your webhook URL is:

https://api.molted.email/v1/hooks/{urlToken}

The token can't be rotated in place: delete the mapping and create it again.

The token is a credential: anyone holding it can run the mapping's actions. Create and update return it. List and get return it only to a caller whose role may change inbound hooks (an admin or the owner, or a key one of them created, with manage or admin scope). Anyone else, a member or a viewer or their keys, gets the mapping with urlToken: null.

Every /v1/agent/inbound-hooks route refuses a mailbox-scoped key (403 mailbox_scope_denied). Create, update and delete need manage (or admin) scope; list, get, logs and test need read. There are no MCP tools for inbound hooks; use the CLI or the API.

Email path syntax

The emailPath field uses dot notation with array index support to extract the email address from any JSON payload structure:

ProviderEmail path
Clerkdata.email_addresses[0].email_address
Stripedata.object.email
Supabase Authrecord.email
CustomAny valid dot-notation path

Field mappings

Map fields from the incoming payload to contact metadata:

{
  "name": "data.first_name",
  "company": "data.organization.name",
  "plan": "data.metadata.plan"
}

Mapped fields are stored as contact metadata (via the sync_contact action). All mapped fields, name included, are merged into the metadata; a mapped name or firstName also sets the contact's name.

The extracted email may be a plain address or a display-name form (Jane Doe <jane@example.com>). The receiver only trims and lowercases it and checks that it contains an @. A new contact is stored as the bare address, lowercased, with the domain in its ASCII form (a Unicode or fullwidth domain is converted and a trailing dot dropped), the same canonical form the Lists API stores. The delivery log's extractedEmail, the receiver's email in its response and the contactEmail passed to trigger_journey keep the lowercased form as extracted (for example jane doe <jane@example.com>).

Action types

Actions execute sequentially in the order configured.

ActionDescriptionParameters
sync_contactUpsert contact with mapped fields: finds the contact by any spelling of the address (case, +tag, Gmail dots, display name) and updates it, or creates it. A mapped name (or firstName) replaces the contact's name; mapped fields are merged into its metadataNone
subscribe_to_listAdd contact to a listlistId (required), requireConfirmation (optional, default false)
trigger_journeyFire an event to start a journeyeventName (required)

If an action fails, subsequent actions still execute. Failed actions are logged but don't block the webhook response.

subscribe_to_list fails the same way as a missing list (List <id> not found) when the list is archived: an archived list refuses every new subscriber, from this action and from POST /v1/agent/lists/:id/subscribers alike.

Double opt-in for subscribe_to_list

subscribe_to_list sits behind a public, token-authenticated form URL, so by default anyone who has the URL can subscribe any address they type in. Two safeguards apply regardless of requireConfirmation:

  • An address that has unsubscribed from the list is never silently reactivated by a form submission. With requireConfirmation: false (the default), a resubmission of an unsubscribed address is a no-op -- it stays unsubscribed. With requireConfirmation: true, a resubmission starts a fresh confirmation cycle instead of reactivating directly. This holds for every spelling the Lists API treats as the same address, and after the contact was deleted and created again or had its email changed: the unsubscribe outlives the contact. It also holds for the other Gmail domain (jane@googlemail.com after jane@gmail.com unsubscribed, and the reverse).
  • An address whose other Gmail domain is already active on the list is not added a second time (one mailbox, one subscription), and one whose other Gmail domain is still pending gets no second confirmation.
  • A suppressed address (bounced, complained, or manually suppressed) is never activated by this action, on or off confirmation.

The public webhook response never reveals which of these happened -- the action always reports status: "ok" unless the webhook mapping itself is misconfigured (e.g. an unknown listId).

Set "requireConfirmation": true on the action to require the address owner to confirm before they're subscribed -- useful for a public waitlist or signup form where you don't want to let someone subscribe a third party's address. A confirmation email is not sent directly by the webhook; instead the address goes to pending and a list.subscribe.pending journey event is emitted (the same event the Lists API emits for its own double opt-in). Configure a journey on that trigger event to send the confirmation email, using the event's confirmationUrl field -- see Lists: Double opt-in for the journey setup. Resubmitting the same address while it is still pending does not send a second confirmation email, and an address that was sent a confirmation for the same list in the last 24 hours through any of your hooks is not sent another (plus-tags and Gmail dots count as the same address; the action reports deduped in the delivery log, and the delivery still answers processed). A confirmation for a different list is not affected. A hook sends at most 200 confirmation emails per rolling 24 hours; past that, the subscribe_to_list action reports failed ("Daily confirmation email limit reached for this hook") in the delivery log, nothing goes pending, and no confirmation is sent until older ones age out. Both limits exist so a leaked URL token cannot be used to mail strangers through your sender.

Managing webhooks

# List all inbound webhook mappings
molted inbound-hooks list

# Get details for a specific webhook
molted inbound-hooks get <id>

# Update a webhook (e.g., disable it). Takes the create flags too;
# --action and --field-map replace the existing lists, not append to them
molted inbound-hooks update <id> --enabled false

# Delete a webhook
molted inbound-hooks delete <id>

# View recent delivery logs (CLI default 20; the API default is 50)
molted inbound-hooks logs <id> --limit 20

# Dry-run a sample payload: no side effects
molted inbound-hooks test <id> --payload '{"data":{"email":"a@b.com"}}'

Testing a webhook mapping (dry run)

Before pointing a real provider at the receiver URL, test the mapping against a sample payload. This runs the same email and field extraction a real delivery would, and reports the actions it would take -- but doesn't execute any of them: no contact upsert, no list subscription, no journey event, and no delivery log row.

Via CLI

molted inbound-hooks test <id> --payload '{"data":{"email_addresses":[{"email_address":"a@b.com"}],"first_name":"Ada"}}'

# Or from a file
molted inbound-hooks test <id> --payload @sample-payload.json

Via API

POST /v1/agent/inbound-hooks/:id/test
{
  "payload": { "data": { "email": "a@b.com", "first_name": "Ada" } }
}
{
  "wouldSucceed": true,
  "enabled": true,
  "extracted": { "email": "a@b.com", "fields": { "name": "Ada" } },
  "actions": [
    { "type": "sync_contact", "description": "Upsert contact with mapped fields" }
  ]
}

A subscribe_to_list entry also carries listId and requireConfirmation, and a trigger_journey entry carries eventName. When wouldSucceed is false the response also has an error.

If the sample payload doesn't yield a valid email at emailPath, wouldSucceed is false and actions is empty -- a real delivery with that payload wouldn't run any action either. If the mapping is disabled, wouldSucceed is false and enabled is false -- a real delivery would be rejected (422) before any action runs.

Security model

This MVP does not perform provider-side signature verification (Svix, HMAC, etc.). The receiver endpoint is authenticated by the URL token alone -- anyone with the URL can trigger the configured actions. Treat tokens as secrets:

  • Paste the URL directly into the provider dashboard; avoid logging or committing it
  • If a URL leaks, delete and recreate the webhook mapping to rotate the token
  • Per-token rate limit: 120 logged deliveries in a trailing minute. Past that, deliveries get 429 { "status": "rejected", "error": "Rate limit exceeded for this webhook" } (rejected requests don't count toward the limit)

Receiver responses

POST /v1/hooks/:token (on the API host, no other auth) answers:

StatusBody
200{ "status": "processed" | "partial", "email", "actionsExecuted": [{ "type", "status": "ok" | "failed", "error"? }] }
200{ "status": "failed", "error": "Could not extract email from payload" }
404{ "status": "rejected", "error": "Unknown webhook" }
422{ "status": "rejected", "error": "Webhook is disabled" }
429Rate limited, see above
500{ "status": "failed", "error": "Internal processing error" }

Signature verification is tracked as a post-MVP enhancement.

Delivery logs

Each webhook delivery is logged with (fields id, webhookId, receivedAt, sourceIp, payloadHash, extractedEmail, extractedFields, status, error, actionsExecuted, createdAt):

  • Timestamp and source IP (the first X-Forwarded-For value)
  • Processing status: processed, partial (at least one action failed) or failed (no valid email found). Requests answered 404, 422 or 429 are not logged.
  • The extracted email and the extracted field values (not the raw payload -- see below). Each field value is capped at 2000 characters of its JSON form; a longer one is replaced with "[truncated: N bytes, type T]"
  • A sha256 hash of the exact bytes received, so a delivery can be verified byte-for-byte once you have the original payload again (a support ticket, the sender's own copy)
  • Per-action execution results
  • Error messages for failed actions

This log row never stores the raw payload -- it can carry far more than a mapping is configured to pull out (a full Stripe or Clerk object, for example). The extracted fields plus the payload hash are enough to understand what a delivery did, and to check a payload you get hold of later against test matches. This is about the log row specifically, not every table: a trigger_journey action still passes the full raw payload into the journey event it creates (so journey trigger_conditions can match against it), same as before this change -- that's unrelated to the delivery log.

Retention: delivery logs older than 30 days are deleted automatically. A GDPR contact deletion (POST /v1/me/delete/contact) keeps the log rows but scrubs every row that carries the address, in the extracted email, the fields or the action results: extractedEmail becomes null, extractedFields {} and actionsExecuted [].

molted inbound-hooks logs <id> --limit 10

API routes

MethodPathDescription
POST/v1/agent/inbound-hooksCreate a mapping (name, emailPath, optional source, fieldMappings, actions)
GET/v1/agent/inbound-hooksList mappings
GET/v1/agent/inbound-hooks/:idGet one mapping
PATCH/v1/agent/inbound-hooks/:idUpdate; also takes enabled. actions and fieldMappings replace the stored values
DELETE/v1/agent/inbound-hooks/:idDelete (returns { "deleted": true })
GET/v1/agent/inbound-hooks/:id/logs?limit=Delivery logs, newest first (default 50)
POST/v1/agent/inbound-hooks/:id/testDry run, body { "payload": {...} }
POST/v1/hooks/:tokenThe public receiver your provider calls

Provider setup examples

Clerk

  1. Create the webhook mapping:
    molted inbound-hooks create \
      --name "Clerk user.created" \
      --source clerk \
      --email-path "data.email_addresses[0].email_address" \
      --field-map "name=data.first_name" \
      --action "sync_contact" \
      --action "subscribe_to_list:<your-list-id>"
  2. In the Clerk Dashboard, go to Webhooks and add a new endpoint
  3. Paste your Molted webhook URL
  4. Subscribe to the user.created event

Stripe

  1. Create the webhook mapping:
    molted inbound-hooks create \
      --name "Stripe customer.created" \
      --source stripe \
      --email-path "data.object.email" \
      --field-map "name=data.object.name" \
      --field-map "stripeId=data.object.id" \
      --action "sync_contact"
  2. In the Stripe Dashboard, go to Developers > Webhooks
  3. Add your Molted webhook URL
  4. Select the customer.created event