My element API endpoint throws a 404 when I'm logged out of the CP, but works fine when I'm logged in.
When logged out it throws a regular 404 with stack trace exactly as any other non-existing url, when logged in it spits out JSON as it should be.
HTTP 404 – Not Found – yii\web\NotFoundHttpException
Template not found: news.json
Notably the front-end of the page works fine always..this just affects the element API.
I tried clearing craft caches + all cookies, still the same. Found nothing suspicious in web.log, phperrors.log or web-404.log I tried it with a very simple element-api.php and it still produces the same issue.
For example, even this element-api.php does not work:
<?php
use craft\elements\Entry;
return [
'endpoints' => [
'news.json' => function() {
return [
'elementType' => Entry::class,
'criteria' => ['section' => 'news'],
'transformer' => function(Entry $entry) {
return [
'title' => $entry->title,
];
},
];
},
]
];
(copied straight from the docs. The section "news" exists in my DB and has valid entries.)
Any idea what could be the cause of this or where to further investigate?
This is on Craft 3.1.12.