Skip to content Skip to footer navigation

REST API

The Content REST API is a read-only API for delivering content from Statamic to your frontend, external apps, SPAs, and numerous other possible sources. Content is delivered as JSON data.

(If you're interested in GraphQL, we have that too.)

Enable the API#

To enable the REST API, add the following to your .env file:

STATAMIC_API_ENABLED=true

Or you can enable it for all environments in config/statamic/api.php:

'enabled' => true,

You will also need to enable the resources you want to be available. For security, they're all disabled by default.

Enable resources#

You can enable resources (ie. Collections, Taxonomies, etc.) in your config/statamic/api.php config:

'resources' => [
'collections' => true,
'taxonomies' => true,
// etc
]

Enable specific sub-resources#

If you want more granular control over which sub-resources are enabled within a resource type (ie. enabling specific Collection queries only), you can use array syntax:

'resources' => [
'collections' => [
'articles' => true,
'pages' => true,
// 'events' => false, // Sub-resources are disabled by default
],
'taxonomies' => true,
// etc.
]

Endpoints#

https://yourdomain.tld/api/{endpoint}
You may send requests to the following endpoints:

Customizing the API URL#

You may customize the route in your API config file or with an environment variable.

// config/statamic/api.php
'route' => 'not_api',
STATAMIC_API_ROUTE=not_api

Filtering#

Enabling filters#

For security, filtering is disabled by default. To enable, you'll need to opt in by defining a list of allowed_filters for each sub-resource in your config/statamic/api.php config:

'resources' => [
'collections' => [
'articles' => [
'allowed_filters' => ['title', 'status'],
],
'pages' => [
'allowed_filters' => ['title'],
],
'events' => true, // Enable this collection without filters
'products' => true, // Enable this collection without filters
],
'taxonomies' => [
'topics' => [
'allowed_filters' => ['slug'],
],
'tags' => true, // Enable this taxonomy without filters
],
// etc.
],

For endpoints that don't have sub-resources (ie. users), you can define allowed_filters at the top level of that resource config:

'resources' => [
'users' => [
'allowed_filters' => ['name', 'email'],
],
],

Using filters#

You may filter results by using the filter query parameter.

/endpoint?filter[{field}:{condition}]={value}

You may use the conditions available to the collection tag. eg. contains, is, isnt (or not), etc. For example:

/endpoint?filter[title:contains]=awesome&filter[featured]=true

This would filter down the results to where the title value contains the string "awesome", and the featured
value is true. When you omit the condition, it defaults to is.

Advanced filtering config#

You can also allow filters on all enabled sub-resources using a * wildcard config. For example, here we'll enable only the articles, pages, and products collections, with title filtering enabled on each, in addition to status filtering on the articles collection specifically:

'resources' => [
'collections' => [
'*' => [
'allowed_filters' => ['title'], // Enabled for all collections
],
'articles' => [
'allowed_filters' => ['status'], // Also enable on articles
],
'pages' => true,
'products' => true,
],
],

If you've enabled filters using the * wildcard config, you can disable filters on a specific sub-resource by setting allowed_filters to false:

'resources' => [
'collections' => [
'*' => [
'allowed_filters' => ['title'], // Enabled for all collections
],
'articles' => [
'allowed_filters' => false, // Disable filters on articles
],
'pages' => true,
'products' => true,
],
],

Or you can enable endpoints and filters on all sub-resources at once by setting both enabled and allowed_filters within your * wildcard config:

'resources' => [
'collections' => [
'*' => [
'enabled' => true, // All collection endpoints enabled
'allowed_filters' => ['title'], // With filters enabled for all
],
],
],

Sorting#

You may sort results by using the sort query parameter:

/endpoint?sort=field

You can sort in reverse by prefixing the field with a -:

/endpoint?sort=-field

You may sort by multiple fields by comma separating them. The reverse flag can be combined with any field:

/endpoint?sort=one,-two,three

You can sort nested fields using the -> operator, like this:

/endpoint?sort=nested->field

Selecting fields#

You may specify which top level fields should be included in the response.

/endpoint?fields=id,title,content

You may also use array syntax:

/endpoint?fields[]=id&fields[]=title&fields[]=content

On the Entry and Asset endpoints, fields will also be honored when fetching a single item, not just when listing them.

Pagination#

Results will be paginated into 25 items per page by default. You may specify the items per page and which page you are viewing with the limit and page parameters:

/endpoint?limit=10&page=1

The response will contain your data, links to easily get next/previous URLs, and meta information for more easily creating a paginator.

{
"data": [
{...},
{...},
],
"links": {
"first": "/endpoint?limit=10&page=1",
"last": "/endpoint?limit=10&page=3",
"prev": null,
"next": "/endpoint?limit=10&page=2",
},
"meta": {
"current_page": 1,
"from": 1,
"to": 10,
"total": 29,
"per_page": 10,
"path": "/endpoint",
}
}

Ping#

GET /api/ping

A simple health check endpoint. It returns pong, and is available whenever the REST API is enabled, regardless of which resources are enabled.

{
"ping": "pong"
}

Sites#

GET /api/sites

Gets all configured sites. This resource is disabled by default. You can enable it with resources.sites in your config/statamic/api.php config:

'resources' => [
'sites' => true,
],
{
"data": [
{
"handle": "default",
"name": "Default",
"locale": "en_US",
"short_locale": "en",
"url": "http://example.com/"
}
]
}

Collections#

GET /api/collections

Gets all collections.

{
"data": [
{
"handle": "blog",
"title": "Blog",
"structure": null,