Headless API Reference
The headless API lives in the core-forms/v1 namespace and uses the site API key for submissions. It’s separate from the administrator API in cf/v1, which manages forms and reads entries.
Turn on the Headless API module and the form’s Headless mode before you call it.
Endpoints
| Method | Route | Access |
|---|---|---|
GET |
/wp-json/core-forms/v1/forms/{id-or-slug} |
Public, for headless forms |
POST |
/wp-json/core-forms/v1/forms/{id-or-slug}/submit |
X-Core-Forms-Key header |
GET |
/wp-json/core-forms/v1/embed.js |
Public |
For products, see the Storefront API. To manage forms, see the REST API Reference.
Get a Form
curl -i "https://cms.example.com/wp-json/core-forms/v1/forms/123"
{
"id": 123,
"slug": "contact",
"title": "Contact",
"html": "<form>...</form>",
"fields": [
{ "name": "email", "type": "email", "required": true, "label": "Email", "options": [] },
{
"name": "topics",
"type": "checkbox",
"required": false,
"label": "Topics",
"options": [{ "value": "sales", "label": "Sales" }]
}
],
"messages": { "success": "Thank you! We will be in touch soon." },
"submit_url": "https://cms.example.com/wp-json/core-forms/v1/forms/123/submit",
"requires_captcha": false,
"captcha": {}
}
| Key | Contents |
|---|---|
id, slug, title |
The form’s identity |
html |
The rendered form |
fields |
Each field’s name, type, required, label and options |
messages |
The form’s messages |
submit_url |
The submit endpoint |
captcha |
The captchas this form checks, each with its public site key |
requires_captcha |
true when a Turnstile or reCAPTCHA site key is saved, even if Turnstile is off for this form |
Submit a Form
curl -i "https://cms.example.com/wp-json/core-forms/v1/forms/123/submit" \
-H "Content-Type: application/json" \
-H "X-Core-Forms-Key: $CORE_FORMS_API_KEY" \
--data '{"name":"Ada","email":"ada@example.com","_cf_page_url":"https://www.example.com/contact"}'
- Send a JSON object with
Content-Type: application/json, ormultipart/form-datafor files. - The form always comes from the URL. An
idin the query or body doesn’t select it. - Send only uploads in file fields. JSON can’t carry files.
- Send the key only in the header. A query parameter isn’t accepted.
- Use field names as keys and arrays for multi-value fields.
- Keys ending in
[]are treated like the name without it. - Keys that aren’t form fields aren’t stored.
- When you forward browser input, fix the form on your server and accept only plain values and lists.
- Field data can total up to 60 KiB.
These keys have special meanings:
| Key | Use |
|---|---|
_cf_page_url |
The page URL for referrer variables |
_cf_h{id} |
Optional honeypot. Must be empty if sent |
cf-turnstile-response |
Turnstile token |
g-recaptcha-response |
reCAPTCHA v3 token |
Two optional headers let a trusted server pass the visitor’s IP:
X-Core-Forms-Proxy-Secret: the proxy secret.X-Core-Forms-Client-IP: one IP address.
A WordPress nonce isn’t needed. The endpoint creates one after it checks the key, so an old _wpnonce in cached HTML does no harm.
Responses
An accepted submission returns 200:
{
"message": { "type": "success", "text": "Thank you! We will be in touch soon." },
"hide_form": false
}
A form that redirects adds redirect_url. A response to spam can also be 200, so a success doesn’t prove an entry was saved.
A validation failure returns 422:
{
"message": { "type": "error", "text": "Please fill in the required fields. (Field: Email)" },
"field": "email",
"error": true
}
Request and setup errors use the WordPress REST format, where message is a string:
{
"code": "cf_invalid_api_key",
"message": "Invalid API key.",
"data": { "status": 401 }
}
Handle both shapes of message. Show fallback text when message or field is absent.
Status Codes
| Status | Code or cause | Meaning |
|---|---|---|
200 |
Accepted | The processor accepted the request |
400 |
rest_invalid_json |
The JSON body is malformed |
400 |
cf_invalid_client_ip |
The proxy sent a missing or invalid IP |
400 |
cf_unreadable_body |
A multipart body has no boundary |
401 |
cf_invalid_api_key |
The key is missing or wrong |
401 |
cf_invalid_proxy_secret |
The proxy secret is wrong |
403 |
cf_headless_disabled |
Headless mode is off for the form |
404 |
cf_unknown_form |
No form matches the ID or slug |
404 |
rest_no_route |
The module is off or the URL is wrong |
413 |
cf_body_too_large |
The body is over PHP’s post_max_size |
422 |
cf_files_need_multipart |
A file field got a value without an upload |
422 |
cf_unknown_file_field |
The form has no field for that file |
422 |
cf_uploads_disabled |
The File Uploads module is off |
422 |
Validation or processing | A field, captcha, limit, duplicate or size check failed |
500 |
cf_processor_no_response |
The processor returned no response. Check the server log |
503 |
cf_missing_api_key |
The site has no API key |
Rate limits also return 422, not 429.
CORS
The routes allow GET, POST and OPTIONS, with the Content-Type and X-Core-Forms-Key headers.
- A filled Allowed origins list is enforced on the form routes, and JSONP is off for them.
- A single
*allows any origin. With the list empty, the request’s origin is reflected. - The Storefront API isn’t governed by the list.
- Requests from servers and scripts aren’t affected.
Use credentials: 'omit' for browser requests. The API doesn’t need cookies.