<p><code>getPost()</code> will search the request’s POST data, but you are setting the parameter values as query string params, so you should be using <code>getQuery()</code>.</p>

<pre class="lang-php prettyprint-override"><code>'studentNumber' =&gt; craft()-&gt;request-&gt;getQuery('studentNumber'),
'email' =&gt; craft()-&gt;request-&gt;getQuery('email'),
</code></pre>

CC BY-SA 3.0
2016-07-26T14:17:43.523Z
Thanks, Brandon. Can't believe I missed that. Much appreciated.
andrew-caulfield
CC BY-SA 3.0
2016-07-26T14:25:09.843Z
Can I ask one last thing? If I wanted to return a matrix in the response that is associated with the entry. Is this something that can be done?
andrew-caulfield
CC BY-SA 3.0
2016-07-26T17:30:15.537Z
@Anderscc Yes. Other questions have touched on that which you can refer to as examples, e.g. http://craftcms.stackexchange.com/q/15995/9 (or feel free to post a new question if you're still having trouble with it)
Brandon Kelly
CC BY-SA 3.0
2016-07-26T14:12:16.360Z
2016-07-26T14:12:16.360Z
Brandon Kelly
<p>I'm trying to return just one entry from Element API based on custom fields created?</p>

<pre><code>return [
    'endpoints' =&gt; [
        'students.json' =&gt; [
            'elementType' =&gt; 'Entry',
                'criteria' =&gt; [
                    'studentNumber' =&gt; craft()-&gt;request-&gt;getPost('studentNumber'),
                    'email' =&gt; craft()-&gt;request-&gt;getPost('email'),
                    'section' =&gt; 'students',
                ],
                'transformer' =&gt; function(EntryModel $entry) {
                return [
                    'studentNumber' =&gt; $entry-&gt;studentNumber,
                    'email' =&gt; $entry-&gt;email,
                ];
            }
        ]
    ]
];
</code></pre>

<p>The Fields are <code>studentNumber</code> and <code>email</code> but it seems to be returning everything. Even when specifying <code>first =&gt; true</code></p>

<p>Anybody point me in the right direction on this? I'd imagine I'm missing something obvious?</p>

<p>Even hitting the url <code>students.json?studentNumber=001</code> is returning everything.</p>

<entries><plugins><plugin-elementapi>
Query Entry Using multiple custom Fields Element API
# Query Entry Using multiple custom Fields Element API

(Asked by: username_0 on 2016-07-26)

I'm trying to return just one entry from Element API based on custom fields created?
return [
    'endpoints' => [
        'students.json' => [
            'elementType' => 'Entry',
                'criteria' => [
                    'studentNumber' => craft()->request->getPost('studentNumber'),
                    'email' => craft()->request->getPost('email'),
                    'section' => 'students',
                ],
                'transformer' => function(EntryModel $entry) {
                return [
                    'studentNumber' => $entry->studentNumber,
                    'email' => $entry->email,
                ];
            }
        ]
    ]
];

The Fields are studentNumber and email but it seems to be returning everything. Even when specifying first => true
Anybody point me in the right direction on this? I'd imagine I'm missing something obvious?
Even hitting the url students.json?studentNumber=001 is returning everything.

**Tags:** entries, plugins, plugin-elementapi


---

## 1 answers

### Answer by username_1 on 2016-07-26. Score: 3 | Accepted answer

getPost() will search the request’s POST data, but you are setting the parameter values as query string params, so you should be using getQuery().
'studentNumber' => craft()->request->getQuery('studentNumber'),
'email' => craft()->request->getQuery('email'),

> **Comments:**
> **username_0**: Thanks, Brandon. Can't believe I missed that. Much appreciated.  
> **username_0**: Can I ask one last thing? If I wanted to return a matrix in the response that is associated with the entry. Is this something that can be done?  
> **username_1**: @Anderscc Yes. Other questions have touched on that which you can refer to as examples, e.g. http://craftcms.stackexchange.com/q/15995/9 (or feel free to post a new question if you're still having trouble with it)  

---

