<p>If you set the <code>elementType</code> to <code>User</code>, then the transformer will have a <a href="https://craftcms.com/classreference/models/UserModel" rel="nofollow"><code>UserModel</code></a> object passed in like so:</p>

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

return [
    'endpoints' =&gt; [
        'players.json' =&gt; [
            'elementType' =&gt; 'User',
            'criteria' =&gt; ['group' =&gt; 'player'],
            'transformer' =&gt; function(\Craft\UserModel $user) {
                return [
                    'username' =&gt; $user-&gt;username,
                    'jsonUrl' =&gt; UrlHelper::getUrl("player/{$user-&gt;id}.json")
                ];
            },
        ]
    ]
];
</code></pre>

CC BY-SA 3.0
2016-04-18T17:47:10.970Z
Thanks for getting back to me Brad: I get this:

Property "Craft\UserModel." is not defined.
Graham Winston
CC BY-SA 3.0
2016-04-18T18:01:54.557Z
Did you get that error before or after my edit?
Brad Bell
CC BY-SA 3.0
2016-04-18T18:03:54.790Z
Hi Brad, no all good, thanks a bunch for the help! It would be really helpful to see a full example with specific user profiles JSON like the entries is layed out :) Thanks again!
Graham Winston
CC BY-SA 3.0
2016-04-18T17:45:06.370Z
2016-04-18T17:47:47.497Z
2016-04-18T17:47:47.497Z
Brad Bell
<p>I am attempting to build an application where Craft handles all of the API based data (JSON). I am using the <a href="https://github.com/pixelandtonic/ElementAPI" rel="nofollow">Element API</a>. I can't find an example anywhere online that outputs Users.</p>

<p>I am trying to output some basics first before I start outputting the custom Matrix fields etc. Here is my <code>elementapi.json</code>: </p>

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

return [
    'endpoints' =&gt; [
        'players.json' =&gt; [
            'elementType' =&gt; 'User',
            'criteria' =&gt; ['group' =&gt; 'player'],
            'transformer' =&gt; function(EntryModel $entry){
                return [
                    'username' =&gt; $entry-&gt;$username,
                    'jsonUrl' =&gt; UrlHelper::getUrl("player/{$entry-&gt;id}.json")
                ];
            },
        ]
    ]
];
</code></pre>

<p>Any help or an example with some custom matrix user fields would be much appreciated! Thanks a bunch!</p>

CC BY-SA 3.0
2016-04-18T17:46:15.157Z
Hi Brad, thanks for editing there, sorry I left the namespace out, that is actually *is* in my elementapi.php . I am just getting a blank page at the moment when I reference mysite.dev.com/players.json
Graham Winston
<plugin-elementapi><json>
Element API User example
# Element API User example

(Asked by: username_0 on 2016-04-18)

I am attempting to build an application where Craft handles all of the API based data (JSON). I am using the Element API. I can't find an example anywhere online that outputs Users.
I am trying to output some basics first before I start outputting the custom Matrix fields etc. Here is my elementapi.json: 
 [
        'players.json' => [
            'elementType' => 'User',
            'criteria' => ['group' => 'player'],
            'transformer' => function(EntryModel $entry){
                return [
                    'username' => $entry->$username,
                    'jsonUrl' => UrlHelper::getUrl("player/{$entry->id}.json")
                ];
            },
        ]
    ]
];

Any help or an example with some custom matrix user fields would be much appreciated! Thanks a bunch!

**Tags:** plugin-elementapi, json

> **Comments:**
> **username_0**: Hi Brad, thanks for editing there, sorry I left the namespace out, that is actually *is* in my elementapi.php . I am just getting a blank page at the moment when I reference mysite.dev.com/players.json  

---

## 1 answers

### Answer by username_1 on 2016-04-18. Score: 2 | Accepted answer

If you set the elementType to User, then the transformer will have a UserModel object passed in like so:
 [
        'players.json' => [
            'elementType' => 'User',
            'criteria' => ['group' => 'player'],
            'transformer' => function(\Craft\UserModel $user) {
                return [
                    'username' => $user->username,
                    'jsonUrl' => UrlHelper::getUrl("player/{$user->id}.json")
                ];
            },
        ]
    ]
];

> **Comments:**
> **username_0**: Thanks for getting back to me Brad: I get this:  Property "Craft\UserModel." is not defined.  
> **username_1**: Did you get that error before or after my edit?  
> **username_0**: Hi Brad, no all good, thanks a bunch for the help! It would be really helpful to see a full example with specific user profiles JSON like the entries is layed out :) Thanks again!  

---

