/ api reference
Domains
Every environment has a default domain. A custom domain serves an environment of the project or redirects to another of its domains. It's pending until its DNS records are in place, then active, with HTTPS certificates issued automatically.
- get/projects/{projectId}/domainsList domains
- post/projects/{projectId}/domainsAdd a domain
- patch/projects/{projectId}/domains/{domainId}Update a domain
- delete/projects/{projectId}/domains/{domainId}Delete a domain
- post/projects/{projectId}/domains/{domainId}/refreshRefresh a domain
List domains
/api/v1/projects/{projectId}/domainsEvery domain of the project, default ones included, with the environment it serves or the domain it redirects to. A custom domain that is not active yet carries the DNS records to create (dnsRecords) and what is still wrong (verificationErrors).
Requires Viewer key or above (workspace.read)
Parameters
projectIdstringin pathrequired
Responses
200The project's environments and domains.Response fields
environmentsobject[]required2 fields
idstringrequirednamestringrequired
domainsobject[]required12 fields
idstringrequiredenvironmentIdstringrequiredhostnamestringrequiredisDefaultbooleanrequiredstatus"pending" | "active" | "error"requiredcloudflareHostnameIdstring | nullrequiredlastCheckedAtstring | nullrequiredcreatedAtstringrequiredenvironmentNamestringrequiredredirectobject | nullrequired3 fields
toDomainIdstringrequiredtoHostnamestringrequiredstatusCode301 | 302 | 307 | 308required
dnsRecordsobject[] | nullrequired4 fields
type"CNAME" | "ALIAS" | "TXT"requirednamestringrequiredvaluestringrequiredpurpose"routing" | "ownership" | "certificate"required
verificationErrorsstring[]required
404No such project in this workspace.
Add a domain
/api/v1/projects/{projectId}/domainsAdds a custom domain that serves an environment (target.kind: environment) or redirects to another domain of the project (target.kind: redirect, with a 301, 302, 307 or 308). It starts pending: create the records in dnsRecords at your DNS provider, then call Refresh until it is active. HTTPS certificates are issued automatically.
Requires Developer key or above (domains.write)
Parameters
projectIdstringin pathrequired
Body
hostnamestringrequiredat most 253 characters
targetobjectrequired2 shapes
One of:
kind: "environment"
kind"environment"requiredenvironmentIdstringrequireduuid
kind: "redirect"
kind"redirect"requiredtoDomainIdstringrequireduuid
statusCode301 | 302 | 307 | 308required
Responses
201The created domain.Response fields
idstringrequiredenvironmentIdstringrequiredhostnamestringrequiredisDefaultbooleanrequiredstatus"pending" | "active" | "error"requiredcloudflareHostnameIdstring | nullrequiredlastCheckedAtstring | nullrequiredcreatedAtstringrequiredenvironmentNamestringrequiredredirectobject | nullrequired3 fields
toDomainIdstringrequiredtoHostnamestringrequiredstatusCode301 | 302 | 307 | 308required
dnsRecordsobject[] | nullrequired4 fields
type"CNAME" | "ALIAS" | "TXT"requirednamestringrequiredvaluestringrequiredpurpose"routing" | "ownership" | "certificate"required
verificationErrorsstring[]required
402Every custom domain your plan includes is in use (quota: custom_domains).Body: see Errors
404No such project in this workspace.409That hostname is already in use.422The target is an environment or a domain of another project, or a redirect to a domain that itself redirects.
Update a domain
/api/v1/projects/{projectId}/domains/{domainId}Changes its hostname, its target, or both. A new hostname goes back to pending and needs its DNS records; the old one keeps serving until the new one is registered. Domains redirecting to this one follow it to its new environment.
Requires Developer key or above (domains.write)
Parameters
projectIdstringin pathrequireddomainIdstringin pathrequired
Body
hostnamestringat most 253 characters
targetobject2 shapes
One of:
kind: "environment"
kind"environment"requiredenvironmentIdstringrequireduuid
kind: "redirect"
kind"redirect"requiredtoDomainIdstringrequireduuid
statusCode301 | 302 | 307 | 308required
Responses
200The updated domain.Response fields
idstringrequiredenvironmentIdstringrequiredhostnamestringrequiredisDefaultbooleanrequiredstatus"pending" | "active" | "error"requiredcloudflareHostnameIdstring | nullrequiredlastCheckedAtstring | nullrequiredcreatedAtstringrequiredenvironmentNamestringrequiredredirectobject | nullrequired3 fields
toDomainIdstringrequiredtoHostnamestringrequiredstatusCode301 | 302 | 307 | 308required
dnsRecordsobject[] | nullrequired4 fields
type"CNAME" | "ALIAS" | "TXT"requirednamestringrequiredvaluestringrequiredpurpose"routing" | "ownership" | "certificate"required
verificationErrorsstring[]required
400An environment's default domain can't be renamed, moved or redirected.404No such project or domain in this workspace.409That hostname is already in use.422The target breaks a rule (see Add a domain).502The new hostname was refused; the domain keeps its old one.
Delete a domain
/api/v1/projects/{projectId}/domains/{domainId}The domain stops serving at once.
Requires Developer key or above (domains.write)
Parameters
projectIdstringin pathrequireddomainIdstringin pathrequired
Responses
204Deleted.400Cannot delete an environment's default domain.404Project or domain not found.409Other domains redirect to this one.
Refresh a domain
/api/v1/projects/{projectId}/domains/{domainId}/refreshChecks the domain's DNS and certificate again and returns its new status. Calls closer than 10 seconds apart for the same domain return the last result without checking again.
Requires Developer key or above (domains.write)
Parameters
projectIdstringin pathrequireddomainIdstringin pathrequired
Responses
200The domain, as of the check.Response fields
idstringrequiredenvironmentIdstringrequiredhostnamestringrequiredisDefaultbooleanrequiredstatus"pending" | "active" | "error"requiredcloudflareHostnameIdstring | nullrequiredlastCheckedAtstring | nullrequiredcreatedAtstringrequiredenvironmentNamestringrequiredredirectobject | nullrequired3 fields
toDomainIdstringrequiredtoHostnamestringrequiredstatusCode301 | 302 | 307 | 308required
dnsRecordsobject[] | nullrequired4 fields
type"CNAME" | "ALIAS" | "TXT"requirednamestringrequiredvaluestringrequiredpurpose"routing" | "ownership" | "certificate"required
verificationErrorsstring[]required
404No such project or domain in this workspace.