FlatpageDocs

curl

Every API call from the command line.

Set the key and two shortcuts once:

export FLATPAGE_API_KEY=fpk_...
API=https://flatpage.app/v1
AUTH="Authorization: Bearer $FLATPAGE_API_KEY"
# Your plan and today's usage
curl -sS "$API/me" -H "$AUTH"

# Publish an HTML file, a zipped site or a PDF (up to 25 MB this way)
curl -sS -X POST "$API/sites?linkName=spring-menu" -H "$AUTH" -H "Content-Type: text/html" --data-binary @index.html
curl -sS -X POST "$API/sites" -H "$AUTH" -H "Content-Type: application/zip" --data-binary @site.zip
curl -sS -X POST "$API/sites" -H "$AUTH" -H "Content-Type: application/pdf" --data-binary @menu.pdf

# Update a site in place (same link)
curl -sS -X PUT "$API/sites/spring-menu" -H "$AUTH" -H "Content-Type: text/html" --data-binary @index.html

# List sites, one site, its views
curl -sS "$API/sites" -H "$AUTH"
curl -sS "$API/sites/spring-menu" -H "$AUTH"
curl -sS "$API/sites/spring-menu/stats" -H "$AUTH"

# Check a link name, rename, delete
curl -sS "$API/link-names/summer-menu" -H "$AUTH"
curl -sS -X PUT "$API/sites/spring-menu/link-name" -H "$AUTH" -H "Content-Type: application/json" -d '{"linkName":"summer-menu"}'
curl -sS -X DELETE "$API/sites/summer-menu" -H "$AUTH"

Zip a build folder so index.html is at the top level of the zip:

(cd dist && zip -qr ../site.zip .)

Get just the link with jq:

curl -sS -X PUT "$API/sites/spring-menu" -H "$AUTH" -H "Content-Type: application/zip" \
  --data-binary @site.zip | jq -r '.site.url // "processing: \(.uploadId)"'