Sites API
We have an API that can be used to manage your Statamic Sites in your statamic.com account. This is most useful with our Platform Plan, which you can contact us directly about for more information.
Authentication#
To access the sites API, you'll need to create a token in your statamic.com account. All of the following endpoints require that your request contains an Authorization header with your token preceded by Bearer.
Example Headers#
| Header Name | Header Value |
|---|---|
Authorization |
Bearer 44|seLDYsDrqyxS2cT8PYremnysuqrovpYHSJ1lzjb3 |
Accept |
application/json |
Using Laravel's HTTP Facade#
If you are using Laravel's Http facade to make your requests, you can use the acceptJson() and withToken() helper methods to make simple JSON requests with your bearer token:
Http::acceptJson()
->withToken($token)
->post('https://statamic.com/api/v1/sites', $payload);
For more info, read more about headers and bearer tokens in Laravel.
Endpoints#
Sites Index#
GET https://statamic.com/api/v1/sites#
Example Output#
{
"data": [
{
"name": "Wayne's World",
"key": "pg4x2qrly2my8dl1",
"domains": [
"waynesworld.ca"
],
"created_at": "2021-11-19 09:32:52"
},
{
"name": "Bobby's World",
"key": "1o0xe7rzdd9wq58j",
"domains": [
"bobbysworld.ca"
],
"created_at": "2021-11-19 09:33:10"
}
]
}
Create Site#
POST https://statamic.com/api/v1/sites#
Params#
| Param | Required | Example |
|---|---|---|
name |
yes | Jurassic World |
domain |
no | jurassicworld.ca |
domains |
no | ["jurassicworld.ca", "staging.jurassicworld.ca"] |
To license more than one domain (for example, a production domain and a staging domain) provide a domains array instead of a single domain. The first domain in the array is treated as the production domain and the rest as testing domains. You may provide domain or domains, but not both.
Example Output#
{
"data": {
"name": "Jurassic World",
"key": "pwkknrxl6y7z1n9v",
"domains": [
"jurassicworld.ca",
"staging.jurassicworld.ca"
],
"created_at": "2021-11-18 19:45:41"
}
}
Update Site#
PATCH https://statamic.com/api/v1/sites/[your-site-key-here]#
Any param you provide will override the site's current value. Params you leave out are left untouched. Providing domain or domains replaces all of the site's existing domains.
Params#
| Param | Required | Example |
|---|---|---|
name |
no | Jurassic World |
domain |
no | jurassicworld.ca |
domains |
no | ["jurassicworld.ca", "staging.jurassicworld.ca"] |
Example Output#
{
"data": {
"name": "Jurassic World",
"key": "pwkknrxl6y7z1n9v",
"domains": [
"jurassicworld.ca",
"staging.jurassicworld.ca"
],
"created_at": "2021-11-18 19:45:41"
}
}
Delete Site#
DELETE https://statamic.com/api/v1/sites/[your-site-key-here]#
Example Output#
{
"message": "Site [pwkknrxl6y7z1n9v] deleted."
}