/v1/apps/{app_id}/custom-domains/{domain_id}/applyAuthSet up the custom domain's DNS records in one step with a short-lived Cloudflare or DigitalOcean API token.
Reads the zone through the provider's API and plans both records: `create`, or `skip` when already there. Nothing is ever changed or deleted, and only names at or under the custom host are written (Cloudflare records are DNS-only, not proxied). Anything in the way (another CNAME at the host, A/MX/TXT records where the CNAME must go) refuses the whole apply with 409 and the plan, before anything is written. `dry_run: true` returns the plan and changes nothing; `dry_run: false` writes exactly that plan and runs a check straight away (the records are usually `propagating` for a few minutes). The token is used for this request only: never stored, logged, queued or returned; revoke it afterwards (`warnings` says so when it could see more than this zone).
Path parameters
app_id*stringId of the app.
domain_id*string · uuidId of the domain.
Headers
Idempotency-Key*stringRequired. Opaque client-generated string (1-256 chars, `[A-Za-z0-9._:-]`). A retry with the same key and body (the token is not part of the comparison) replays the first response instead of writing again, for 24 hours.
Request body
provider*enum (2)DNS provider to write the records to: `cloudflare` or `digitalocean`.
Example: "cloudflare"
token*stringA short-lived API token with DNS edit rights for the zone (Cloudflare: Zone → DNS → Edit for that zone; DigitalOcean: a token with the domain scopes). Used for this request only: never stored, logged or returned. Revoke it afterwards.
Example: "cf-token-from-your-dashboard"
zonestring · hostnameThe zone to write in (the host or one of its parents). Defaults to the detected zone.
Example: "acme.com"
dry_run*boolean`true`: return the plan and change nothing. `false`: write exactly that plan, then check the domain.
Example: true
Response · 200 The plan (dry run), or the plan with each record's `result` and the domain after a fresh check.
domain_id*string · uuidId of the custom domain.
Example: "1d2c3b4a-5e6f-4a7b-8c9d-0e1f2a3b4c5d"
hostname*string · hostnameThe custom auth hostname.
Example: "auth.acme.com"
provider*objectDNS provider the records were written to: `cloudflare` or `digitalocean`.
Example: "cloudflare"
zone*string · hostnameThe provider zone the records go in.
Example: "acme.com"
dry_run*booleanTrue when this was a preview: no record was written.
Example: true
applied*booleanTrue when the records were written.
Example: false
plan*arrayOne item per DNS record: what was (or would be) done.
conflicts*arrayExisting records that block the plan.
counts*objectcreate*numberRecords created (or that would be).
Example: 2
skip*numberRecords already correct, left alone.
Example: 0
failed*numberRecords that could not be written.
Example: 0
warnings*array`token_scope_broader_than_zone`: the token could see other zones; revoke it now. `partially_applied`: some records were written and some failed (see each item's `error`).
Example: []
domain*objectThe domain right after the apply, with a fresh check. Null on a dry run.
Example
Request
POST https://api.auth.productcraft.co/v1/apps/{app_id}/custom-domains/{domain_id}/apply
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
{
"provider": "cloudflare",
"token": "cf-token-from-your-dashboard",
"zone": "acme.com",
"dry_run": true
}import { Auth } from "@productcraft/auth";
// Admin routes read PRODUCTCRAFT_API_KEY; consumer routes need no key
const auth = new Auth();
const customDomainApplyResult = await auth.admin.app("3f0c3c1e-8a2b-4c55-9d3f-0a1b2c3d4e5f").customDomains.apply("3f0c3c1e-8a2b-4c55-9d3f-0a1b2c3d4e5f", { dry_run: true, provider: "cloudflare", token: "cf-token-from-your-dashboard" });auth.admin.app(…).customDomains.apply(domainId, params, options?): Auth.CustomDomainApplyResult
Response
{
"domain_id": "1d2c3b4a-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
"hostname": "auth.acme.com",
"provider": "cloudflare",
"zone": "acme.com",
"dry_run": true,
"applied": false,
"plan": [
{
"action": "create",
"purpose": "routing",
"type": "CNAME",
"host": "auth.acme.com",
"name": "auth",
"value": "edge.auth.productcraft.co",
"ttl": 3600,
"existing": [],
"conflicts": [
{
"code": "cname_foreign",
"severity": "blocking",
"message": "auth.acme.com already points at acme.netlify.app. Change that CNAME to edge.auth.productcraft.co, or use another name.",
"suggested_value": "edge.auth.productcraft.co"
}
],
"note": null,
"result": "created",
"error": null
}
],
"conflicts": [
{
"code": "cname_foreign",
"severity": "blocking",
"message": "auth.acme.com already points at acme.netlify.app. Change that CNAME to edge.auth.productcraft.co, or use another name.",
"suggested_value": "edge.auth.productcraft.co",
"purpose": "routing",
"host": "auth.acme.com"
}
],
"counts": {
"create": 2,
"skip": 0,
"failed": 0
},
"warnings": [],
"domain": {}
}