Add a custom domain
method
POST
host
strait.
version
/v1
resource
/
POST /v1/domains
Auth: secret key as Authorization: Bearer. Server-side only.
Coming soon: custom domains aren't switched on yet. Until they are, this endpoint answers enabled: false (the list) or 503 domains_not_enabled.
Request
Adds a subdomain you own (for example links.yourcompany.com) and creates it at Cloudflare. The answer lists the DNS records to add: a CNAME to the target, a TXT record that proves you own the domain, and a TXT record for the HTTPS certificate. Owners, admins and members; Scale and Enterprise only; at most 5 per workspace. Adds and removes share a limit of 10, then 1 every 6 minutes, per workspace.
Body (JSON)
tenantIdstring- Required with a dashboard session
hostnamerequired string- A subdomain, without https:// or a path
Response
- 201 Added; add the DNS records shown
- 400 Not a usable hostname (a bare domain, an IP, one of our hosts, or malformed)
- 401 Missing or invalid secret key or session
- 402 plan_required: custom domains are part of the Scale plan
- 403 Viewers cannot add domains
- 409 Already added to a Strait workspace, or the workspace already has 5
- 429 Too many domain changes (Retry-After: 360)
- 502 Cloudflare didn't answer; nothing was saved
- 503 domains_not_enabled, or domains_read_only
curl -X POST https://strait.link/v1/domains \
-H "Authorization: Bearer $SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"hostname": "links.hilltop.example"
}'const res = await fetch('https://strait.link/v1/domains', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SECRET_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"hostname": "links.hilltop.example"
}),
});
const data = await res.json();
console.log(res.status, data);import os
import requests
res = requests.post(
"https://strait.link/v1/domains",
headers={"Authorization": f"Bearer {os.environ['SECRET_KEY']}"},
json={
"hostname": "links.hilltop.example",
},
)
print(res.status_code, res.json())<?php
// Plain PHP with ext-curl, no packages. In Laravel, Http::withToken($secretKey)->post($url, $body) sends the same request.
$ch = curl_init('https://strait.link/v1/domains');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SECRET_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'hostname' => 'links.hilltop.example',
], JSON_THROW_ON_ERROR),
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
echo $status, PHP_EOL;
print_r(json_decode($response, true));import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
// Java 17+, java.net.http only (no dependencies).
public class Main {
public static void main(String[] args) throws Exception {
String body = """
{
"hostname": "links.hilltop.example"
}
""";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://strait.link/v1/domains"))
.header("Authorization", "Bearer " + System.getenv("SECRET_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> res = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(res.statusCode() + " " + res.body());
}
}package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`{
"hostname": "links.hilltop.example"
}`)
req, err := http.NewRequest(http.MethodPost, "https://strait.link/v1/domains", body)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("SECRET_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(res.StatusCode, string(data))
}The response, printed
{
"hostname": "links.hilltop.example",
"verified": false,
"status": "pending_dns",
"records": [
{
"type": "CNAME",
"name": "links.hilltop.example",
"value": "fallback.strait.link",
"purpose": "Sends your links to Strait"
},
{
"type": "TXT",
"name": "_cf-custom-hostname.links.hilltop.example",
"value": "5cc07c04-ea62-4a5a-95f0-419334a875a4",
"purpose": "Proves you own the domain"
},
{
"type": "TXT",
"name": "_acme-challenge.links.hilltop.example",
"value": "ca3-574923932a82475cb8592200f1a2a23d",
"purpose": "Lets us issue its HTTPS certificate"
}
]
}