<p>Change</p>



<pre class="lang-php prettyprint-override"><code>function (EntryModel $user)
</code></pre>

<p>to </p>

<pre class="lang-php prettyprint-override"><code>function (UserModel $user)
</code></pre>

<p>You were passing in a user to a function that’s expecting an EntryModel. That’s the reason for the error you are getting.</p>

CC BY-SA 3.0
2015-09-22T12:56:17.247Z
Thank you, Brandon and Luke. I knew I wasn't passing in the correct class... just wasn't sure what the correct usage was. This gets me back on the road!
Damon
CC BY-SA 3.0
2015-09-22T05:15:55.040Z
2015-09-22T11:45:51.790Z
2015-09-22T11:45:51.790Z
Luke Holder
<p>I am attempting to use the <a href="https://github.com/pixelandtonic/ElementAPI" rel="nofollow">ElementAPI</a> to check if a user is logged in or not. I've used the ElementAPI before to check/get entries for a given section, but never for user-based entries.</p>

<p>Here is my <code>elementapi.php</code> file:</p>

<pre><code>&lt;?php
namespace Craft;

return [
    'endpoints' =&gt; [
        'user/current.json' =&gt; [
            'elementType' =&gt; 'User',
            'criteria' =&gt; [
                'foo' =&gt; 'bar', // Not sure what to do here.
            ],
            'transformer' =&gt; function (EntryModel $user) {
                // Not sure about this either...
                if ($user-&gt;isCurrent) {
                    return [
                        'status' =&gt; true
                    ];
                } else {
                    return [
                        'status' =&gt; false
                    ];
                }
            },
        ]
    ]
];
</code></pre>

<p>I'm getting to the plugin, but It really is not happy with what I'm giving it:</p>

<pre><code>Argument 1 passed to Craft\ConfigService::Craft\{closure}() must be an instance of Craft\EntryModel, instance of Craft\UserModel given
</code></pre>

<p>Pretty sure it has something to do with the criteria?</p>

<users><current-user><plugin-elementapi>
How can I interact with Users via the ElementAPI?
# How can I interact with Users via the ElementAPI?

(Asked by: username_0 on 2015-09-22)

I am attempting to use the ElementAPI to check if a user is logged in or not. I've used the ElementAPI before to check/get entries for a given section, but never for user-based entries.
Here is my elementapi.php file:
 [
        'user/current.json' => [
            'elementType' => 'User',
            'criteria' => [
                'foo' => 'bar', // Not sure what to do here.
            ],
            'transformer' => function (EntryModel $user) {
                // Not sure about this either...
                if ($user->isCurrent) {
                    return [
                        'status' => true
                    ];
                } else {
                    return [
                        'status' => false
                    ];
                }
            },
        ]
    ]
];

I'm getting to the plugin, but It really is not happy with what I'm giving it:
Argument 1 passed to Craft\ConfigService::Craft\{closure}() must be an instance of Craft\EntryModel, instance of Craft\UserModel given

Pretty sure it has something to do with the criteria?

**Tags:** users, current-user, plugin-elementapi

---

## 1 answers

### Answer by username_1 on 2015-09-22. Score: 4 | Accepted answer

Change
function (EntryModel $user)

to 
function (UserModel $user)

You were passing in a user to a function that’s expecting an EntryModel. That’s the reason for the error you are getting.

> **Comments:**
> **username_0**: Thank you, Brandon and Luke. I knew I wasn't passing in the correct class... just wasn't sure what the correct usage was. This gets me back on the road!  

---

