Skip to main content

CMS API

We use Wagtail for our CMS, which comes with a nice REST API tightly integrated with Django REST Framework. Our endpoint for CMS content is /cms-api - the default Wagtail configuration is /api/v2, so if you come across other Wagtail guides (such as this YouTube tutorial), just substitute /cms-api in place of /api/v2.

Overview

Endpoints

  • /cms-api/pages/
  • /cms-api/images/
  • /cms-api/documents/

The pattern is very similar to places and events - the root endpoints (e.g. /cms-api/pages) is the list view while appending the id (e.g. /cms-api/pages/3) returns the detail view.

The CMS API is read-only, all requests should be GET s.

Cookbook

Only select one field in the response

export DOMAIN=https://api.vibemap.com

curl "${DOMAIN}/cms-api/pages/3/?fields=cover_image"

Only select certain fields in the response (the underscore by itself would select no fields):

 curl "${DOMAIN}/cms-api/pages/?fields=_,id,title,html_url"

Retrieve every field, except for a select few (prefix with a minus sign -):

 curl "${DOMAIN}/cms-api/pages/?fields=*,-first_published_at"

Restrict query to certain models (currently, guides.GuidePage is the only one):

 curl "${DOMAIN}/cms-api/pages/?type=guides.GuidePage"

Limit the number of results:

 curl "${DOMAIN}/cms-api/pages/?limit=5"

Ordering results:

 curl "${DOMAIN}/cms-api/pages/?order=title"
# to reverse, prefix with a minus sign
curl "${DOMAIN}/cms-api/pages/?order=-title"

Filtering:

 curl "${DOMAIN}/cms-api/pages/?slug=some-page-slug"
# children of some other page
curl "${DOMAIN}/cms-api/pages/?child_of=<id of parent page>"
# descendants of other page
curl "${DOMAIN}/cms-api/?descendant_of=<id of child page>"

Searching:

 curl "${DOMAIN}/cms-api/pages/?search=<search term>"