FlaresendDocs
Admin API

Set up a domain

Onboard one of a project's domains in Cloudflare Email Sending, with its DNS records and delivery events.

POST/v1/admin/projects/{slug}/domains/{domain}/setupAdmin key

Does in one call what Deploy steps 3 and 4 do by hand. It is what the dashboard's Set up in Cloudflare menu item and Add domain dialog call. It only works with the admin key: project API keys get 403 admin_only, because it changes DNS with the mailer's own Cloudflare token.

The mailer needs a CF_API_TOKEN secret with Zone Read, Email Sending Edit, DNS Edit and Queues Edit, and the CF_ACCOUNT_ID var. See Configuration.

It runs these steps in order and reports each one:

  1. sending domain: adds the domain to Email Sending on its Cloudflare zone, unless it is already there.
  2. dns: one step per record Cloudflare lists for the domain (SPF, DKIM, return path). Adds each record that is missing.
  3. dmarc: only when Cloudflare's list has no DMARC record. If neither _dmarc.<domain> nor _dmarc.<zone> has one, adds v=DMARC1; p=none at _dmarc.<domain>.
  4. delivery events: subscribes the domain's delivery events to the flaresend-events queue, unless a subscription for this zone and domain already exists.

It never changes or deletes a DNS record that is already there. When a different record is in the way (a CNAME at the same name, or another SPF, DKIM or DMARC TXT record), the step is reported as conflict for you to fix by hand. Records are added unproxied. It is safe to run again: finished steps report exists.

Path parameters

slugstringpathrequired

The project slug.

domainstringpathrequired

One of the project's allowedDomains. Add it to the project first with Update a project.

Response

Status 200. A step that fails does not fail the request; check each step's status.

domainstring

The domain, lowercased.

zonestring

The Cloudflare zone that holds it, for example acme.com for mail.acme.com.

stepsStep[]

What happened, in order.

Show step properties
stepstring

sending domain, dns, dmarc or delivery events.

status'created' | 'exists' | 'conflict' | 'skipped' | 'failed'

created: done now. exists: already in place. conflict: another record is in the way. skipped: delivery events only, when CF_ACCOUNT_ID is not set. failed: the Cloudflare API call failed.

detailstring

A sentence explaining the status, or the Cloudflare error.

record{ type, name, content }

For DNS steps, the record that was wanted.

recordobject

The domain's fresh verification status after setup: domain, verification (onboarded, pending, missing or unknown), details and checkedAt. The same as an entry from List domains, without defaultFrom.

Errors

StatusCodeWhen
403admin_onlyCalled at /v1/domains/:domain/setup with a project API key.
404project_not_foundNo project has this slug.
404domain_not_in_projectThe domain is not in the project's allowedDomains.
422cf_token_missingThe mailer has no CF_API_TOKEN secret.
422zone_not_foundThe token can't see a Cloudflare zone for the domain. The domain's DNS must be on Cloudflare in the mailer's account.
422cloudflare_api_errorFinding the zone or creating the sending domain failed. message has Cloudflare's error.