Custom Domains API Endpoints
The Custom Domains API enables programmatic registration, automated Domain Control Validation (DCV), TLS certificate tracking, and routing configuration for branded apex domains, subdomains, and reverse proxy subpaths.
1. List Workspace Domains
Retrieve all custom domains and subpath proxies registered to the active organization.
GET /api/v1/domains
Request Headers
Authorization: Bearer <token>
Accept: application/jsonResponse Example (HTTP 200 OK)
{
"code": 0,
"data": [
{
"id": "dom_7f8a92b1",
"domain": "link.brand.com",
"routingType": "cname",
"pathPrefix": null,
"status": "active",
"sslStatus": "active",
"rootRedirectUrl": "https://brand.com",
"notFoundRedirectUrl": "https://brand.com/404",
"createdAt": 1774180000,
"verifiedAt": 1774180300
},
{
"id": "dom_9c12e84d",
"domain": "brand.com",
"routingType": "subpath_proxy",
"pathPrefix": "/go",
"status": "active",
"sslStatus": "not_applicable",
"rootRedirectUrl": "https://brand.com/deals",
"notFoundRedirectUrl": "https://brand.com/404",
"createdAt": 1774190000,
"verifiedAt": 1774190100
}
]
}2. Register Custom Domain
Register a new branded domain or subpath proxy route under the active workspace.
POST /api/v1/domains
Request Body Parameters
Validated against CreateCustomDomainSchema in shared/schemas/saas.ts.
| Field | Type | Required | Description |
|---|---|---|---|
domain |
string |
Yes | Fully qualified domain name (e.g. link.brand.com or brand.com). Must be lowercase without protocols or paths. |
routingType |
string |
No | Routing architecture mode: 'cname' (DNS delegation, default), 'subpath_proxy' (reverse proxy subpath), or 'dedicated_domain'. |
pathPrefix |
string |
Conditional | Required if routingType is subpath_proxy. Subdirectory path prefix (e.g. "/go" or "/links"). Cannot use reserved system paths (/api, /dashboard, /auth, /_nuxt, /docs). |
Request Example (Dedicated CNAME)
curl -X POST "https://shaf.app/api/v1/domains" \
-H "Authorization: Bearer $SHAF_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"domain": "link.brand.com",
"routingType": "cname"
}'const token = process.env.SHAF_API_TOKEN;
const res = await fetch("https://shaf.app/api/v1/domains", {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
domain: "link.brand.com",
routingType: "cname",
}),
});
const data = await res.json();
console.log(data);Response Example (HTTP 201 Created)
{
"code": 0,
"data": {
"id": "dom_7f8a92b1",
"domain": "link.brand.com",
"routingType": "cname",
"status": "pending",
"sslStatus": "pending_validation",
"verificationRecords": [
{
"type": "CNAME",
"name": "link.brand.com",
"value": "cname.shaf.app"
},
{
"type": "TXT",
"name": "_cf-custom-hostname.link.brand.com",
"value": "39dfa01e-8b12-4cf4-9128-4e89712a0f88"
}
],
"rootRedirectUrl": "https://brand.com",
"notFoundRedirectUrl": "https://brand.com/404"
}
}3. Verify Domain DNS & SSL Status
Trigger an on-demand verification check against Cloudflare for SaaS edge infrastructure.
GET /api/v1/domains/:id/verify (or POST /api/v1/domains/:id/verify)
Path Parameters
id(string, required): Unique custom domain identifier (e.g.dom_7f8a92b1).
Response Example (HTTP 200 OK)
{
"code": 0,
"data": {
"id": "dom_7f8a92b1",
"domain": "link.brand.com",
"status": "active",
"sslStatus": "active",
"verified": true,
"lastCheckedAt": 1774180420
}
}4. Update Domain Settings
Update root fallback and 404 redirect destinations for an existing domain.
PATCH /api/v1/domains/:id
Request Body Parameters
Validated against UpdateCustomDomainSchema in shared/schemas/saas.ts.
| Field | Type | Description |
|---|---|---|
rootRedirectUrl |
string | null |
Redirect target when visiting the bare domain without a slug. |
notFoundRedirectUrl |
string | null |
Fallback URL when visiting nonexistent or expired links. |
Request Example
curl -X PATCH "https://shaf.app/api/v1/domains/dom_7f8a92b1" \
-H "Authorization: Bearer $SHAF_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"rootRedirectUrl": "https://brand.com/home",
"notFoundRedirectUrl": "https://brand.com/help/link-not-found"
}'5. Delete Custom Domain
Remove a custom domain, purge its edge TLS certificate, and invalidate associated KV routing bindings.
DELETE /api/v1/domains/:id
Path Parameters
id(string, required): Domain record identifier.
Response Example (HTTP 200 OK)
{
"code": 0,
"data": {
"deleted": true,
"id": "dom_7f8a92b1",
"domain": "link.brand.com"
}
}Error Response Matrix
| Status | Code | Constant | Meaning & Mitigation |
|---|---|---|---|
400 |
40010 |
INVALID_DOMAIN_FORMAT |
Domain string contains illegal characters, uppercase letters, or protocol prefixes. |
400 |
40011 |
RESERVED_SUBPATH_PREFIX |
Selected pathPrefix collides with reserved system routes (/api, /dashboard, etc.). |
403 |
40302 |
QUOTA_EXCEEDED |
Active domain count has reached your subscription plan quota. |
404 |
40402 |
DOMAIN_NOT_FOUND |
Domain identifier does not exist or belongs to another organization. |
409 |
40902 |
DOMAIN_ALREADY_EXISTS |
Domain is already claimed by another active workspace. |
422 |
42201 |
DCV_CHALLENGE_FAILED |
DNS CNAME or TXT validation failed during verification attempt. Check DNS records. |