NightmailDocs
Docs

Set where an address’s mail goes

patch/v1/inbound/addresses/{addressId}/flow

Change where one address’s mail goes, in one version. Changes the route for the address’s own address and its two-way rule together: one transaction and one routing version, so all of it is saved or none of it. Omitted fields stay as they are, a field equal to what is saved writes nothing, and when nothing changes the version stays. deliver replaces only the route’s destinations (a paused route stays paused). Send the version from getInboundOverview or getRouting as If-Match; a stale one is refused with 409 and nothing changes.

Needs Receiving rules: write on the whole workspace. A person needs to be an owner or admin. Not a temporary agent token.

Example

import { createClient } from '@nightmail/sdk/client';
import { setInboundAddressFlow } from '@nightmail/sdk';

const client = createClient({
  baseUrl: 'https://nightmail.dev',
  auth: scheme => scheme.scheme === 'bearer'
    ? process.env.NIGHTMAIL_API_KEY
    : undefined,
});

const result = await setInboundAddressFlow({
  client,
  path: {
    "addressId": "address_123"
  },
  body: {},
  throwOnError: true,
});

console.log(result.data);
curl --request PATCH \
  --url 'https://nightmail.dev/v1/inbound/addresses/address_123/flow' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{}'

Parameters

addressIdrequiredpath · string

Opaque inbound address ID (mbx_…).

if-matchheader · string

Apply only if routes and rules are still at this version, from getInboundOverview, GET /v1/routing or a previous ETag.

Request body

SetInboundAddressFlow
endpointsobject[]

New endpoints this change uses, made with it: a refusal or failure makes none of them.

endpoints[].typerequiredstring
endpoints[].namerequiredstring

Endpoint name, unique in the workspace across every type.

endpoints[].urlrequiredstring

As createEndpoint takes it: a Slack or Discord webhook URL, or a public HTTPS URL for a webhook (its signing secret is not returned here).

forwardobject

A new forward: its recipient is asked by this address when it can send the request (else as createEndpoint picks one). deliver and split may name it at once: mail received from the moment they allow it is forwarded, never mail received before. The answer’s forward says whether they were emailed.

forward.namerequiredstring

Endpoint name, unique in the workspace across every type.

forward.addressrequiredstring

Recipient. They confirm with an emailed link, sent from the new address when it can send it (else as createEndpoint picks one), unless preverify applies.

forward.preverifyboolean or string

As createEndpoint takes it: auto skips the confirmation only for an address on a domain this workspace has verified.

deliverstring or string or string[] or null

Where the address's mail goes: the destinations of the route for its own address, as createRoute takes them (inbox, webhook and forward IDs or keys, [] to keep it without an inbox, or 'drop'). Creates the route when there is none; null deletes it.

rulestring

The key of the two-way rule (split or split-by-meaning) on this address that split changes.

splitobject or null

With rule: rewrites that rule. A rule other addresses also run is left as it is for them, and this address gets its own copy under a new key. Without rule: adds a new two-way rule on this address. null, with rule: takes the rule off this address, and deletes it once no address runs it.

split.reciperequiredstring

split, or split-by-meaning to let the AI decide.

split.paramsobject

The fields createRuleFromRecipe takes for this recipe: split { test, value, then, otherwise }, split-by-meaning { meaning, then, otherwise }.

Responses

200Success
InboundAddressFlow
versionrequiredinteger

The routing and rules version after the change, also the ETag; unchanged when nothing changed.

forwardobject

The forward flow.forward made, as getEndpoint returns it.

forward.idrequiredstring

Endpoint ID: mwh_… for a webhook, con_… for Slack, Discord or a forward. Routes list webhooks and forwards by ID.

forward.namerequiredstring

Endpoint name, unique in the workspace across every type. Rules call endpoints.<name>(…).

forward.typerequiredstring
forward.statusrequiredstring

ready: callable. pending: a forward waiting for its recipient to confirm. expired: the confirmation link lapsed. declined: the recipient declined or stopped forwards. paused: deliveries are held.

forward.callrequiredstring

How a rule calls it.

forward.targetrequiredstring

Where it delivers. Slack, Discord and webhook URLs are write-only; only the last four characters are shown.

forward.policyrequiredobject
forward.expiresAtrequiredstring or null

When a pending forward confirmation link expires.

forward.requestFromrequiredstring or null

A forward: the address that emailed its recipient to confirm. null when none was asked (preverified) and for other types.

forward.nextSteprequiredstring

What to do next, for people and agents.

forward.createdAtrequiredstring
forward.confirmationrequiredstring

emailed: its recipient was asked to confirm (requestFrom names who asked); skipped: preverified, ready at once.

routerequiredobject or null

The route for the address's own address, as getRoute returns it; null when there is none.

route.keyrequiredstring or null

Stable key you choose (lowercase letters, digits, hyphens). Config files refer to inbox:<key>, webhook:<key> and forward:<name>.

route.matchrequiredstring

Recipient, case-insensitive: an address (support@acme.com), a local-part pattern (reply+*@acme.com, *-invoices@acme.com) or a catch-all (*@acme.com, or @acme.com). The most specific route wins: exact address, then the pattern with the most literal characters, then the plus-address base, then the catch-all, then the domain default.

route.torequiredstring or string or string[]

Inbox, webhook and forward IDs, [] to keep, or 'drop'.

route.subaddressesrequiredboolean
route.enabledrequiredboolean
route.noterequiredstring
route.idrequiredstring
route.createdAtrequiredstring
rulerequiredstring or null

The two-way rule this change left on the address: the rule it named, its own copy when the rule was shared, or the new rule. null when it was taken off, or no rule was named or added.

400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiError
errorrequiredobject
error.coderequiredstring
error.messagerequiredstring
error.requestIdrequiredstring
error.fieldstring
error.retryablerequiredboolean
error.resetAtstring

Next capacity change for a Hosted rolling send limit.

error.detailsobject[]

Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch).

error.requiredobject

On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.