<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>

CC BY-SA 4.0
2019-06-16T16:40:51.500Z
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.
fbnntt
CC BY-SA 4.0
2019-06-16T16:12:31.867Z
2019-06-16T16:12:31.867Z
Brandon Kelly
<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>

<craft3><plugin-elementapi>
Element API — Endpoint has an invalid elementType
# 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:
 [
        '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:
 [
        '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
'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 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.  

---

