# REST API: How to filter to only get needed fields?

**URL:** <https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426>\
**Category:** Product Support\
**Tags:** mautic-4\
**Created:** [June 24, 2023, 3:06pm UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426 "2023-06-24T15:06:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dross](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dross/32/10015_2.png) [@dross](https://forum.mautic.org/u/dross)\
**Post date:** [June 24, 2023, 3:06pm UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/1 "2023-06-24T15:06:04Z")

</div>

My problem is:  
When getting a list of contacts mautic gives me lot of data that i wont use by default.

What if I get for example: [https://mail.mymautic.com/api/contacts?search=owner:ownerusername&fields=id,firstname,email](https://mail.mymautic.com/api/contacts?search=owner:ownerusername&fields=id,firstname,email) - This retrieves 0 data

But if i retrieve [https://mail.mymautic.com/api/contacts?search=owner:ownerusername](https://mail.mymautic.com/api/contacts?search=owner:ownerusername) this retrieves 50 contacts (with unlimited rows for each one, when i only need 3 id,fn,email.

Is there a way to limit the data exposed so the queries are more performant ? Tried minimal but it didnt work either.

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [June 24, 2023, 8:22pm UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/2 "2023-06-24T20:22:11Z")

</div>

you can add minimal param in query string which should return less fields, but I am not aware of a way which would allow you to return just listed fields at the moment.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [June 25, 2023, 6:57am UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/3 "2023-06-25T06:57:01Z")

</div>

@mzagmajster can you explain the exact param you need to add in query? I have a post open from a long time ago on this as all I really want to get on a query is the contact id and as mentioned above it gives back all custom fields

---

<div class="post-metadata">

**Author:** ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)\
**Post date:** [June 25, 2023, 7:30am UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/4 "2023-06-25T07:30:47Z")

</div>

Hi, according to this docs here: \< [Mautic Developer Documentation](https://developer.mautic.org/#list-contacts) \>, there is minimal parameter, although I see that the numbered of returned fields is still high. I would call it like this: `https://<root-api-url>/api/contacts?minimal=1`

Regards, M.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [June 25, 2023, 7:59am UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/5 "2023-06-25T07:59:19Z")

</div>

Thanks, I checked it out and tested… did not really work, got the entire payload back

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [June 25, 2023, 8:09am UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/6 "2023-06-25T08:09:04Z")

</div>

also tried with minimal=true and still nothing. A pity

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [June 25, 2023, 9:24am UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/7 "2023-06-25T09:24:52Z")

</div>

So I went ahead and wrote a small script that will just extract the contact ID. Still not the best as you are still getting the entire payload back, but you are able to extract just what you want, here is the example and it can be modified to your required needs:

```auto
#!/bin/bash
USERNAME="USERNAME"
PASSWORD="PASSWORD"
REQUEST_URL='https://your-mautic-url.com/api/contacts?where[0][col]=email&where[0][expr]=eq&where[0][val]=email-you@looking.for'
response=$(curl -s -u "$USERNAME:$PASSWORD" "$REQUEST_URL")
contact_id=$(echo "$response" | jq -r '.contacts[].id')
firstname=$(echo "$response" | jq -r '.contacts[].fields.core.firstname.value')
lastname=$(echo "$response" | jq -r '.contacts[].fields.core.lastname.value')

echo "Contact ID: $contact_id"
echo "Contact ID: $contact_id"
echo "First Name: $firstname"
echo "Last Name: $lastname"

```

---

<div class="post-metadata">

**Author:** ![dross](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dross/32/10015_2.png) [@dross](https://forum.mautic.org/u/dross)\
**Post date:** [June 25, 2023, 3:16pm UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/8 "2023-06-25T15:16:49Z")

</div>

This one works at server? So this could be called by api? or in top of this we should write an API? Would be great for a set of PR with this new features…

My workaround was to filter after server request and store that on redis…

---

<div class="post-metadata">

**Author:** ![jorge73](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jorge73/32/12645_2.png) [@jorge73](https://forum.mautic.org/u/jorge73)\
**Post date:** [December 31, 2024, 5:09pm UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/9 "2024-12-31T17:09:13Z")

</div>

Go here: `/<mautic-path>/app/bundles/LeadBundle/Controller/Api/CustomFieldsApiControllerTrait.php` and get only the “all” attributes list:

```auto
    protected function preSerializeEntity(object $entity, string $action = 'view'): void
    {
        if ($entity instanceof CustomFieldEntityInterface) {
            $fields = array(); //#COMMENT THIS $entity->getFields();
            $fields['all'] = $entity->getProfileFields();

            // Temporary hack to address numbers being type casted to float which broke some API implementations because M2 used to return
            // these as strings and values are normalized in a dozen differneet ways throughout LeadModel::setFieldValues methods and became
            // too risky to hotfix
            $fields = $this->fixNumbers($fields);

            $entity->setFields($fields);
        }
    }

```

I had 27kb, now I get 2kb of data and the section “all” contains what I need.

---

<div class="post-metadata">

**Author:** ![ekke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ekke/32/296_2.png) [@ekke](https://forum.mautic.org/u/ekke)\
**Post date:** [May 29, 2026, 2:43pm UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/10 "2026-05-29T14:43:40Z")

</div>

For the records: I just had the same issue, neither /api/contacts?`minimal=true` nor /api/contacts?`select=id,email` preventing the huge arrays being fed back.  
I do think there’s some buggyness.

**BUT here are two nice workarounds:**

A) `minimal=true&select=id` DOES prevent the flood, returns a rather slim amount of data  
Example:

```auto
/api/contacts?minimal=true&select=id 

{"total":"662060","contacts":{"2911715":{"isPublished":true,"dateAdded":"2026-05-29T14:05:23+00:00","id":2911715,"points":0,"fields":{"core":[],"social":[],"personal":[],"professional":[],"all":{"id":"2911715"}}}}}

```

–

B) syntax like `minimal=true&select%5B%5D=id&select%5B%5D=firstname&select%5B%5D=email` even allows you to select additional fields and still stay lean 🙂  
Example:

```auto
/api/contacts?minimal=true&select%5B%5D=id&select%5B%5D=firstname&select%5B%5D=email

{"total":"662060","contacts":{"2911715":{"isPublished":true,"dateAdded":"2026-05-29T14:05:23+00:00","dateModified":"2026-05-29T14:41:14+00:00","modifiedBy":2,"modifiedByUser":"Ekkehard G\u00fcmbel","id":2911715,"points":0,"fields":{"core":{"firstname":{"id":"2","label":"First Name","alias":"firstname","type":"text","group":"core","object":"lead","is_fixed":"1","properties":"a:0:{}","value":"Martina","normalizedValue":"Martina"},"email":{"id":"6","label":"Email","alias":"email","type":"email","group":"core","object":"lead","is_fixed":"1","properties":"a:0:{}","value":"test@test.de","normalizedValue":"test@test.de"}},"social":[],"personal":[],"professional":[],"all":{"id":"2911715","firstname":"Martina","email":"test@test.de"}}}}}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [September 28, 2026, 6:35am UTC](https://forum.mautic.org/t/rest-api-how-to-filter-to-only-get-needed-fields/28426/11 "2026-09-28T06:35:36Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
