API
Export a knowledge base as a static website
Checked against Cloudflare documentation, November 2026.
A script can rebuild the static website of a public knowledge base, for example every night, and publish it on any web server. Static website describes what the website contains and how to publish it by hand. The full reference of the routes is at /api/docs on your instance.
Before you start
Section titled “Before you start”- The knowledge base must have the audience “public”. Other knowledge bases are refused with
staticSiteNotPublic, because a static website has no sign-in. - Exporting a space needs a person’s account with a role in the knowledge base: its space admin, or a member whose organization role manages spaces (not for confidential spaces, which only their space admins export). Guests and service accounts cannot export spaces.
- Create a personal token for that person with the organization area
spacesatviewand the content levelread; see Getting started. - You need the ID of the knowledge base.
GET /api/v1/spaces?type=knowledgeBaselists the knowledge bases the token can read.
-
Start the export with
format: "site". GivesiteUrl, the address the website will be served from, to getsitemap.xml,robots.txtand language links for search engines:sh EXPORT=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \-d '{"format": "site", "siteUrl": "https://help.example.com/"}' \https://wiki.example.com/api/v1/spaces/$SPACE/exports | jq -r .id) -
Wait until the export is built.
stategoes fromqueuedandrunningtoreadyorfailed:sh while :; doSTATE=$(curl -s -H "Authorization: Bearer $TOKEN" https://wiki.example.com/api/v1/exports/$EXPORT | jq -r .state)[ "$STATE" = ready ] && break[ "$STATE" = failed ] && exit 1sleep 10done -
Download the ZIP file:
sh curl -s -H "Authorization: Bearer $TOKEN" -o site.zip https://wiki.example.com/api/v1/exports/$EXPORT/content -
Unpack it and publish the folder, for example on Cloudflare Pages:
sh unzip -o site.zip -d sitenpx wrangler pages deploy site --project-name=helpIn a script, Wrangler reads the Cloudflare API token from
CLOUDFLARE_API_TOKEN(permission Cloudflare Pages Edit) and the account fromCLOUDFLARE_ACCOUNT_ID. Create the project once beforehand, in the dashboard or withnpx wrangler pages project create help.
Articles lie in the ZIP as <number>-<slug>.html, for example 1042-set-up-the-vpn-connection.html. Articles in the default language of the knowledge base lie at the root; the other languages get a folder named after the language, such as de/.
When the export fails
Section titled “When the export fails”A failed export names the reason in errorCode of GET /api/v1/exports/{exportId}:
errorCode |
Meaning |
|---|---|
notPublic |
The audience of the knowledge base changed while the website waited to be built. |
noAccess |
The person lost the permission to export the space. |
tokenRevoked |
The token that started the export was revoked. |
exportDisabled |
A space admin turned export off for the space. |
notEnoughStorage |
The file store ran short of free space. |
interrupted |
The worker was interrupted too often. |
tooLargeToBuild |
Building the website ran out of memory. |
internalError |
An unexpected error; the export failed after all attempts. |
The list can grow; treat an unknown errorCode as a failure.
Starting an export can also be refused:
| Problem | Meaning |
|---|---|
staticSiteNotPublic |
The knowledge base is not public. |
exportRunning |
The person runs another export. Each person runs one export at a time. |
tooManyExports |
The person keeps five finished exports. Delete one under Settings › My account › My exports, or with DELETE /api/v1/exports/{exportId}, which needs a token with the area spaces at manage. |
exportDisabled |
Export is turned off for the space. |
notEnoughStorage |
The file store is too full for the export. |
A new export of the same space in the same format replaces the earlier one, so a nightly script does not pile up exports. A finished export is kept for 7 days, or 24 hours after its first complete download.