Import and Export
Round-trip a whole site as JSON or YAML, and script your backups.
These are the API equivalents of the Export menu in the manager, which makes them the simplest way to back up a site on a schedule.
| Endpoint | What it does |
|---|---|
| GET /api/v1/site/{site}/ | Export. ?dl=json, yaml, csv, zip, or media |
| POST /api/v1/site/{site}/ | Upsert content into an existing site |
| GET /api/v1/manager/sites/{site}/export/ | Export as a downloadable file. ?output=json or yaml |
| POST /api/v1/manager/sites/{site}/export/ | Upsert content into an existing site |
A nightly backup is one call:
Request
curl -H "Authorization: Token $ENINE_TOKEN" \
"https://e9sites.com/api/v1/site/mysite.e9sites.com/?dl=json" \
-o "mysite-$(date +%F).json"
Pushing content back:
Request
curl -X POST -H "Authorization: Token $ENINE_TOKEN" -H "Content-Type: application/json" \
-d @mysite.json \
https://e9sites.com/api/v1/site/mysite.e9sites.com/
import json
import os
import requests
headers = {"Authorization": f"Token {os.environ['ENINE_TOKEN']}"}
base = "https://e9sites.com/api/v1/site/mysite.e9sites.com"
site = requests.get(f"{base}/?dl=json", headers=headers).json()
with open("mysite.json", "w", encoding="utf-8") as handle:
json.dump(site, handle, indent=2)
Two things to know. The format is chosen by the dl or output query parameter, never by an Accept header. And these endpoints are the exception to the usual response shape: they wrap their payload in success and data, where the rest of the API returns the resource directly.