Getting Started
From a fresh TYPO3 installation to the first JSON response.
1. Install
composer require friendsoftypo3/headless
Classic mode: unpack the release into typo3conf/ and
activate it in the Extensions module. The extension ships
without ext_; TYPO3 v14 reads its metadata from
composer..
2. Create a root page + site config
In the backend, create a new page at the root level (the site root). Then go to Sites > Setup and add a site configuration pointing at that page.
Important
Give the API site its own host as base, like
https:// — not a path on the frontend domain
(https://). If the browser should reach the API through
the frontend's origin, let the frontend server proxy a path to the API
host and set it as frontend (Cross-origin requests (CORS)).
3. Add the headless set and switch the site to JSON
Both settings are part of the site configuration:
# config/sites/<identifier>/config.yaml
rootPageId: 1
base: https://api.example.com
dependencies:
- friendsoftypo3/headless
# 0 = NONE, 1 = FULL (always JSON),
# 2 = MIXED (Accept-driven, with the headless-mixed set)
headless: 1
Do not add a root sys_template record (Configuration). The other
sets, the statics for sites without sets and the mixed-mode Accept rule
(Mixed mode and the Accept header) are described there as well.
4. Drop a content element on the page
Add a Text element (or any other standard content element) to the page and save.
5. Fetch the page
curl https://api.example.com/
The response looks like this (abbreviated):
{
"id": 1,
"slug": "/",
"seo": { "title": "Home" },
"breadcrumbs": [{ "title": "Home", "link": "/" }],
"content": {
"colPos0": [{ "id": 1, "type": "text", "content": { "bodytext": "…" } }]
}
}
See Reference: TypoScript helpers for what each field means and where to override it.
Making requests
The API is the TYPO3 site itself: every page URL of the site returns that
page as JSON, so the frontend requests exactly the URL a browser would —
including language prefixes (/de/) and query strings for plugins.
curl -H 'Accept: application/json' https://api.example.com/de/about
Headers
Accept: application/— required on ajson headless: 2(mixed) site, as the whole header (Mixed mode and the Accept header). Harmless on aheadless: 1site, which answers JSON regardless.Content-(orType: application/ x- www- form- urlencoded multipart/for uploads) for POST requests to forms and plugins — bodies are regular TYPO3 request bodies, not JSON, and every hidden field must be echoed back verbatim (see EXT:form and EXT:felogin).form- data Cookie— see Cookies below.- A browser calling the API host from another origin also needs CORS
headers, or a proxy path via
frontend— see Cross-origin requests (CORS).Api Proxy
Endpoints
Besides the page response, the shipped TypoScript answers two extra page types on every page of the site:
| Request | Returns |
|---|---|
/?type=834 | initial: the primary navigation, the language
menu and the login state. Fetch it once per language,
not per page — see Initial data (?type=834). |
/?type=835 | headless_: the sites of the instance that have
headless enabled, with their frontend and API URLs —
see Multiple sites and ?type=835. |
Cookies
Three TYPO3 cookies matter for a headless frontend: fe_
(frontend login session), be_ (backend session — enables the
preview of hidden pages and workspaces) and typo3nonce_* (signs the
__ of login and form submissions). A browser only sends
them to the host that set them, so:
- Requests the browser makes directly to the API host need
credentials: 'include'(fetch, nuxt-typo3:typo3.) orapi. credentials with(axios).Credentials: true api.andexample. com example.are same-site, so the cookies travel with such requests either way. A sharedcom cookieis only needed when the same session has to be visible on the frontend host too — server-side rendering plus client requests, or backend preview; see Multi-Site & URL Configuration.Domain -
Requests the frontend server makes (server-side rendering, e.g. nuxt-typo3) carry none of the browser's cookies. The frontend has to forward the incoming
Cookieheader to TYPO3 and relay TYPO3'sSet-header back to the browser. nuxt-typo3 configures both directions inCookie nuxt.(header names lower-case):config. ts export default defineNuxtConfig({ typo3: { api: { proxyReqHeaders: ['cookie'], // browser -> Nuxt -> TYPO3 proxyHeaders: ['set-cookie'], // TYPO3 -> Nuxt -> browser }, }, })Copied!
Without the forwarded cookies a logged-in user looks anonymous to TYPO3, login and form submissions fail on the request token, and hidden pages stay hidden.
Next steps
- Render the response in a frontend, with nuxt-typo3 examples: Consuming the API.
- Add a top-level field of your own: Adding fields via raw TypoScript.
- Put your SPA on a separate domain (so links in the response point at your frontend, not the API): Multi-Site & URL Configuration.
- Listen to a headless event (e.g. inject a signed CDN URL into every file payload): Events you can listen to.
- Something does not work: Troubleshooting.