Auth API reference

Auth API · Apps

post/v1/apps/{app_id}/custom-domains/{domain_id}/applyAuth

Set 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*string

Id of the app.

domain_id*string · uuid

Id of the domain.

Headers

Idempotency-Key*string

Required. 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*string

A 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 · hostname

The 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 · uuid

Id of the custom domain.

Example: "1d2c3b4a-5e6f-4a7b-8c9d-0e1f2a3b4c5d"

hostname*string · hostname

The custom auth hostname.

Example: "auth.acme.com"

provider*object

DNS provider the records were written to: `cloudflare` or `digitalocean`.

Example: "cloudflare"

zone*string · hostname

The provider zone the records go in.

Example: "acme.com"

dry_run*boolean

True when this was a preview: no record was written.

Example: true

applied*boolean

True when the records were written.

Example: false

plan*array

One item per DNS record: what was (or would be) done.

conflicts*array

Existing records that block the plan.

counts*object
create*number

Records created (or that would be).

Example: 2

skip*number

Records already correct, left alone.

Example: 0

failed*number

Records 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*object

The 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
}

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": {}
}