I'm attempting to fetch SEO meta for entries inside of an element API, roughly following the advice in Element API integration
Below is the exact code in my element-api.php
:
<?php
use craft\elements\Entry;
return [
'endpoints' => [
'api.json' => function() {
return [
'elementType' => Entry::class,
'criteria' => [],
'transformer' => function(Entry $entry) {
$seo = Craft::$app->runAction('seomatic/meta-container/all-meta-containers', [
'uri' => $entry->uri,
'siteId' => null,
'asArray' => true,
])->data;
return $seo;
},
];
},
]
];
If I hit this endpoint directly in a browser - e.g. http://my-url.test/api.json - it returns a response exactly as expected. However, if I try to hit the endpoint using an external GET
requestion with Accept: application/json
(I'm using https://paw.cloud, specifically), I get back an error exception of yii\\web\\ForbiddenHttpException
Is there something about runAction
inside of an Element API call that isn't allowed? Is there something I need to do to allow this in outside requests?