Answers.Body: <p>Your second example has the correct <code>elementType</code> value (<code>Entry::class</code> with a corresponding <code>Entry</code> import at the top of the file). Alternatively you could do</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>'elementType' =&gt; 'craft\elements\Entry',
  </code></pre>
  
  <p>The error you’re getting in that example is because you changed the endpoint to just <code>news.json</code> rather than <code>api/news.json</code>. So the request isn’t getting routed to this endpoint in the first place.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-16T16:40:51.500Z
Answers.Text: Spot on. Thanks for much for this Brandon — got it working now (_seems like it was because of the api/news.json + news.json error_)! 
  
  Really looking forward to using the plugin more and more.
Answers.UserDisplayName: fbnntt
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-16T16:12:31.867Z
Answers.LastActivityDate: 2019-06-16T16:12:31.867Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm trying the Element API for the first time and getting this error message <code>{"error":{"code":404,"message":"Endpoint has an invalid elementType"}}</code></p>
  
  <p>I cannot for the life of me figure out what I'm missing... I've read the docs, followed the Mijingo "Creating an Element API video", read Andrew Welch's post (<a href="https://nystudio107.com/blog/lazy-loading-with-the-element-api-vuejs" rel="nofollow noreferrer">https://nystudio107.com/blog/lazy-loading-with-the-element-api-vuejs</a>) and hunted through Stack Exchange but haven't came across any fixes.</p>
  
  <p>This is from my current <code>element-api.php</code> file:</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  return [
      'endpoints' =&gt; [
          'api/news.json' =&gt; [
              'elementType' =&gt; 'Entry',
              'criteria' =&gt; ['section' =&gt; 'news'],
              'transformer' =&gt; function(EntryModel $entry) {
                  return [
                      'title' =&gt; $entry-&gt;title,
                      'body' =&gt; (string) $entry-&gt;newsText
                  ];
              }
          ],
      ]
  ];
  </code></pre>
  
  <p>Previously, I tried changing the code slightly to:</p>
  
  <pre><code>&lt;?php
  
  use craft\elements\Entry;
  use craft\helpers\UrlHelper;
  
  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,
                          'url' =&gt; $entry-&gt;url,
                          'jsonUrl' =&gt; UrlHelper::url("news/{$entry-&gt;id}.json"),
                          'newsTitle' =&gt; $entry-&gt;newsTitle,
                      ];
                  },
              ];
          },
      ]
  ];
  </code></pre>
  
  <p>but still no luck. With the second block of code the error message I get is <code>Template not found: api/news.json</code></p>
  
  <p>Apologies if I'm missing something completely obvious, this is the first time using the plugin, and I don't know PHP, but following along with the Mijingo video helped me understand what was going on.</p>
  
  <p>If anyone has any suggestions to fix this that would be greatly appreciated!</p>
  
  <p>Cheers</p>
  
Tags: <craft3><plugin-elementapi>
Title: Element API — Endpoint has an invalid elementType
ThreadText: # Element API — Endpoint has an invalid elementType
  
  (Asked by: username_0 on 2019-06-15)
  
  I'm trying the Element API for the first time and getting this error message `{"error":{"code":404,"message":"Endpoint has an invalid elementType"}}`
  
  I cannot for the life of me figure out what I'm missing... I've read the docs, followed the Mijingo "Creating an Element API video", read Andrew Welch's post (<https://nystudio107.com/blog/lazy-loading-with-the-element-api-vuejs>) and hunted through Stack Exchange but haven't came across any fixes.
  
  This is from my current `element-api.php` file:
  
  ```
  <?php
  namespace Craft;
  
  return [
      'endpoints' => [
          'api/news.json' => [
              'elementType' => 'Entry',
              'criteria' => ['section' => 'news'],
              'transformer' => function(EntryModel $entry) {
                  return [
                      'title' => $entry->title,
                      'body' => (string) $entry->newsText
                  ];
              }
          ],
      ]
  ];
  
  ```
  
  Previously, I tried changing the code slightly to:
  
  ```
  <?php
  
  use craft\elements\Entry;
  use craft\helpers\UrlHelper;
  
  return [
      'endpoints' => [
          'news.json' => function() {
              return [
                  'elementType' => Entry::class,
                  'criteria' => ['section' => 'news'],
                  'transformer' => function(Entry $entry) {
                      return [
                          'title' => $entry->title,
                          'url' => $entry->url,
                          'jsonUrl' => UrlHelper::url("news/{$entry->id}.json"),
                          'newsTitle' => $entry->newsTitle,
                      ];
                  },
              ];
          },
      ]
  ];
  
  ```
  
  but still no luck. With the second block of code the error message I get is `Template not found: api/news.json`
  
  Apologies if I'm missing something completely obvious, this is the first time using the plugin, and I don't know PHP, but following along with the Mijingo video helped me understand what was going on.
  
  If anyone has any suggestions to fix this that would be greatly appreciated!
  
  Cheers
  
  **Tags:** craft3, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-16. Score: 2 | Accepted answer
  
  Your second example has the correct `elementType` value (`Entry::class` with a corresponding `Entry` import at the top of the file). Alternatively you could do
  
  ```php
  'elementType' => 'craft\elements\Entry',
  
  ```
  
  The error you’re getting in that example is because you changed the endpoint to just `news.json` rather than `api/news.json`. So the request isn’t getting routed to this endpoint in the first place.
  
  > **Comments:**
  > **username_0**: Spot on. Thanks for much for this username_1 — got it working now (_seems like it was because of the api/news.json + news.json error_)!   Really looking forward to using the plugin more and more.  
  
  ---
  
  