Answers.Body: <p>Probably you need to turn on the <strong>Meta Container Endpoint Access</strong> option in SEOmatic -&gt; Plugin Settings -&gt; Endpoints</p>
  <p>This is intentionally disabled by default, you need to enable it if you intend to use it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-12T16:37:06.630Z
Answers.Text: Thanks Andrew, I ended up finding and implementing your other Stack Overflow post related to this before I saw your comment, but I'll try enabling this plugin setting and if it works I'll make yours as the correct answer.
Answers.UserDisplayName: cmal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-12T16:48:40.663Z
Answers.Text: Enabling "Meta Container Endpoint Access" in the SEOmatic plugin settings did, indeed, do the trick. Are there any pros/cons to this approach vs. your approach in the linked stack overflow post?
Answers.UserDisplayName: cmal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-13T19:55:28.753Z
Answers.Text: The way recommended in that other post saves you an additional and unneeded XHR so... I'd go with that. :)
Answers.UserDisplayName: andrew.welch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-12T16:24:14.483Z
Answers.LastActivityDate: 2021-02-12T16:24:14.483Z
Answers.UserDisplayName: andrew.welch
Answers.Body: <p>I ended up using the pattern described in <a href="https://craftcms.stackexchange.com/questions/32923/how-to-pull-an-entrys-seomatic-meta-tags-with-element-api">How to pull an entry&#39;s SEOmatic meta tags with Element API?</a> which didn't suffer from the same issue.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-12T16:35:37.943Z
Answers.LastActivityDate: 2021-02-12T16:35:37.943Z
Answers.UserDisplayName: cmal
Body: <p>I'm attempting to fetch SEO meta for entries inside of an element API, roughly following the advice in <a href="https://github.com/nystudio107/craft-seomatic/issues/312" rel="nofollow noreferrer">Element API integration</a></p>
  <p>Below is the exact code in my <code>element-api.php</code>:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  use craft\elements\Entry;
  
  return [
      'endpoints' =&gt; [
          'api.json' =&gt; function() {
              return [
                  'elementType' =&gt; Entry::class,
                  'criteria' =&gt; [],
                  'transformer' =&gt; function(Entry $entry) {
                      $seo = Craft::$app-&gt;runAction('seomatic/meta-container/all-meta-containers', [
                          'uri' =&gt; $entry-&gt;uri,
                          'siteId' =&gt; null,
                          'asArray' =&gt; true,
                      ])-&gt;data;
  
                      return $seo;
                  },
              ];
          },
      ]
  ];
  
  </code></pre>
  <p>If I hit this endpoint directly in a browser - e.g. <a href="http://my-url.test/api.json" rel="nofollow noreferrer">http://my-url.test/api.json</a> - it returns a response exactly as expected. However, if I try to hit the endpoint using an external <code>GET</code> requestion with <code>Accept: application/json</code> (I'm using <a href="https://paw.cloud" rel="nofollow noreferrer">https://paw.cloud</a>, specifically), I get back an error exception of <code>yii\\web\\ForbiddenHttpException</code></p>
  <p>Is there something about <code>runAction</code> inside of an Element API call that isn't allowed? Is there something I need to do to allow this in outside requests?</p>
  
Tags: <plugin-elementapi><plugin-seomatic>
Title: Accessing SEOmatic meta via controller action in Element API triggers HTTPForbiddenException
ThreadText: # Accessing SEOmatic meta via controller action in Element API triggers HTTPForbiddenException
  
  (Asked by: username_0 on 2021-02-11)
  
  I'm attempting to fetch SEO meta for entries inside of an element API, roughly following the advice in [Element API integration](https://github.com/nystudio107/craft-seomatic/issues/312)
  
  Below is the exact code in my `element-api.php`:
  
  ```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?
  
  **Tags:** plugin-elementapi, plugin-seomatic
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-02-12. Score: 1 | Accepted answer
  
  Probably you need to turn on the **Meta Container Endpoint Access** option in SEOmatic -> Plugin Settings -> Endpoints
  
  This is intentionally disabled by default, you need to enable it if you intend to use it.
  
  > **Comments:**
  > **username_0**: Thanks Andrew, I ended up finding and implementing your other Stack Overflow post related to this before I saw your comment, but I'll try enabling this plugin setting and if it works I'll make yours as the correct answer.  
  > **username_0**: Enabling "Meta Container Endpoint Access" in the SEOmatic plugin settings did, indeed, do the trick. Are there any pros/cons to this approach vs. your approach in the linked stack overflow post?  
  > **username_1**: The way recommended in that other post saves you an additional and unneeded XHR so... I'd go with that. :)  
  
  ---
  
  ### Answer by username_0 on 2021-02-12. Score: 1
  
  I ended up using the pattern described in [How to pull an entry's SEOmatic meta tags with Element API?](https://craftcms.stackexchange.com/questions/32923/how-to-pull-an-entrys-seomatic-meta-tags-with-element-api) which didn't suffer from the same issue.
  
  
  ---
  
  