Cloudflare Zone Settings Endpoint¶
Authenticated admin endpoint that applies a partial set of Cloudflare zone settings (cache, SSL, security level, minify, etc.) to the zone that hosts a given domain, across the multiple Cloudflare accounts configured in AWS Secrets Manager.
- Method / path:
POST /api/cloudflare/settings - Auth: admin only (
validate_admin). Missing/invalid token ->401; authenticated non-admin ->403. - Source of accounts:
skynet_api.config.cfg.CLOUDFLARE_SETTINGS(list of{mail, token, base_url}dicts loaded from/common/cloudflare). The account identifier surfaced to callers is themailfield.
Request body¶
| Field | Type | Required | Notes |
|---|---|---|---|
domain |
string | yes | Site domain, e.g. example.com. |
cf_account_name |
string | no | The mail of the target account (case-insensitive). Omit to auto-discover the owning account across all configured accounts. |
preset |
string | no* | Named server-side settings bundle (see Presets). Unknown name -> 422. |
settings |
object | no* | Partial settings payload. Unknown keys are rejected with 422 (extra=forbid). |
* At least one of preset or settings is required. If both are
given, settings override the preset field-by-field (e.g. preset sets
ssl=flexible but an explicit settings.ssl=strict wins). An effectively
empty result (no fields to apply) returns 422.
Supported settings fields¶
| Field | Type | Allowed values |
|---|---|---|
cache.cache_level |
string | aggressive, basic, simplified |
cache.browser_cache_ttl |
int | seconds |
cache.edge_cache_ttl |
int | seconds |
security_level |
string | off, essentially_off, low, medium, high, under_attack |
ssl |
string | off, flexible, full, strict |
always_use_https |
bool | mapped to Cloudflare on/off |
development_mode |
bool | mapped to on/off |
minify.css/html/js |
bool | merged into one Cloudflare minify PATCH |
rocket_loader |
bool | mapped to on/off |
http2 |
bool | mapped to on/off |
ipv6 |
bool | mapped to on/off |
Dashboard label -> API value¶
Some dashboard labels do not match the API value you pass here. The most common gotcha is the Caching Level:
| Dashboard (Caching ▸ Configuration ▸ Caching Level) | API cache.cache_level |
|---|---|
| No query string | basic |
| Ignore query string | simplified |
| Standard | aggressive |
SSL/TLS encryption mode Flexible is simply ssl: "flexible".
Presets¶
A preset is a named, server-side bundle of settings applied as a unit, so
callers don't re-send the same body each time. Pass "preset": "<name>"
instead of (or alongside) settings.
| Preset | Applies |
|---|---|
new_domain_defaults |
The standard new-domain config: ssl=flexible + cache.cache_level=simplified (dashboard: SSL/TLS -> Flexible, Caching Level -> "Ignore query string"). |
Presets are defined in src/skynet_api/cloudflare/presets.py; add a new key
there to introduce another bundle. Example request:
{ "domain": "example.com", "preset": "new_domain_defaults" }
Account resolution¶
cf_account_namegiven: matched (case-insensitive) against each account'smail. No match ->422.cf_account_nameomitted: the endpoint queriesGET {base_url}/zones?name={domain}for every configured account and picks the single account that hosts the zone.- Zero matches ->
404. - More than one match ->
409(response lists the matching account mails).
Behaviour¶
Each provided setting becomes a concurrent
PATCH {base_url}/zones/{zone_id}/settings/{setting_name} call (run via
asyncio.gather). Results are aggregated per field. Retries follow the
existing CF_RETRY_STATUSES policy ({429, 500, 502, 503, 504}).
Response¶
200 when all fields applied, or 207 Multi-Status when some failed
(status: "partial", with failed_fields populated). Body shape is the same:
{
"domain": "example.com",
"cf_account_name": "primary@frontstory.com",
"zone_id": "abc123zoneid",
"status": "applied",
"updated_fields": ["cache.cache_level", "ssl"],
"failed_fields": []
}
status |
Meaning |
|---|---|
applied |
Every requested field updated successfully. |
partial |
Some fields failed; see failed_fields[].reason. |
Status codes¶
| Code | When |
|---|---|
| 200 | All settings applied. |
| 207 | Partial: some fields failed (status: "partial", see failed_fields). |
| 401 | Missing / invalid access token. |
| 403 | Authenticated but not an admin. |
| 404 | Domain not hosted on the targeted / any configured account. |
| 409 | Domain resolved to more than one account (ambiguous). |
| 422 | Validation error: unknown account, unknown/empty settings, bad enum. |
| 502 | Cloudflare rejected the request (token scope) or upstream 5xx. |
The token is never echoed in any error body or log line; logs record only
username + domain.
Manual verification¶
Two ready-to-use request bodies are provided:
docs/examples/cloudflare-settings.example.json-- a full explicitsettingspayload exercising every field.docs/examples/cloudflare-settings-new-domain-defaults.example.json-- thenew_domain_defaultspreset (the recurring "standard config when adding a new domain" workflow).
# Replace TOKEN and the host with your environment.
curl -sS -X POST "https://<app-api-host>/api/cloudflare/settings" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data @docs/examples/cloudflare-settings-new-domain-defaults.example.json | jq .
Expected on success: HTTP 200 with "status": "applied" and every applied
field listed in updated_fields (ssl, cache.cache_level for the preset).
To exercise auto-discovery, delete the cf_account_name line from either
payload.