Answers.Body: <p>The issue ended up being related to the yii debug toolbar failing to execute correctly. Disabling it in app.php fixed it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-16T04:26:51.457Z
Answers.Text: Please share your code. I'm experiencing a related issue, instead I've discovered when I remove this line of code ```Craft::$app->getUrlManager()->getMatchedElement()['id']``` in my custom module, my news.json is now visible and the issue is resolved.
Answers.UserDisplayName: Jessica Talzor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-27T11:38:00.797Z
Answers.LastActivityDate: 2019-02-27T11:38:00.797Z
Answers.UserDisplayName: Udo
Body: <p>My element API endpoint throws a 404 when I'm logged out of the CP, but works fine when I'm logged in. </p>
  
  <p>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. </p>
  
  <pre><code>HTTP 404 – Not Found – yii\web\NotFoundHttpException
  Template not found: news.json
  </code></pre>
  
  <p>Notably the front-end of the page works fine always..this just affects the element API.</p>
  
  <p>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. </p>
  
  <p>For example, even this element-api.php does not work:</p>
  
  <pre><code>&lt;?php
  
  use craft\elements\Entry;
  
  return [
      'endpoints' =&gt; [
          'news.json' =&gt; function() {
              return [
                  'elementType' =&gt; Entry::class,
                  'criteria' =&gt; ['section' =&gt; 'news'],
                  'transformer' =&gt; function(Entry $entry) {
                      return [
                          'title' =&gt; $entry-&gt;title,
                      ];
                  },
              ];
          },
      ]
  ];
  </code></pre>
  
  <p>(copied straight from the docs. The section "news" exists in my DB and has valid entries.)</p>
  
  <p>Any idea what could be the cause of this or where to further investigate?</p>
  
  <p>This is on Craft 3.1.12.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-26T16:08:50.803Z
Comments.Text: Can you share your code?
Comments.UserDisplayName: Tony DeStefano
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-26T16:31:10.343Z
Comments.Text: @TonyDeStefano shared above, but I don't think this is the cause of the issue..
Comments.UserDisplayName: Udo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-26T17:50:56.200Z
Comments.Text: Not sure if this is anything, but your endpoint is news.json and your 404 says map.json ...
Comments.UserDisplayName: Tony DeStefano
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-26T18:24:44.523Z
Comments.Text: nah that was just another version of the config. Thanks though for checking!
Comments.UserDisplayName: Udo
Tags: <plugin-elementapi>
Title: Element API throws 404 when not logged into CP
ThreadText: # Element API throws 404 when not logged into CP
  
  (Asked by: username_0 on 2019-02-25)
  
  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.
  
  **Tags:** plugin-elementapi
  
  > **Comments:**
  > **username_1**: Can you share your code?  
  > **username_0**: @username_1 shared above, but I don't think this is the cause of the issue..  
  > **username_1**: Not sure if this is anything, but your endpoint is news.json and your 404 says map.json ...  
  > **username_0**: nah that was just another version of the config. Thanks though for checking!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-02-27. Score: 2 | Accepted answer
  
  The issue ended up being related to the yii debug toolbar failing to execute correctly. Disabling it in app.php fixed it.
  
  > **Comments:**
  > **username_2**: Please share your code. I'm experiencing a related issue, instead I've discovered when I remove this line of code ```Craft::$app->getUrlManager()->getMatchedElement()['id']``` in my custom module, my news.json is now visible and the issue is resolved.  
  
  ---
  
  