Search out the contact ID from a contact Search

Your software
My Mautic version is:3.0
My PHP version is:7.3
My Database type and version is:mysql

Your problem
My problem is:I need a special search when using API to bring in contacts.

Item 1: {"total":1,"contacts":{"1791":{"isPublished":true,"dateAdded":"2021-09-20T00:19:34+00:00","dateModified":

 Item 2:"all":{"id":"1791","points":1999,"last_active":null,"title":"Mr","firstname":"James","lastname":"Chambers","

 my end point: https://mauticsite.com/api/contacts?search=govtom@cox.net";

As you can see above…i am searching the contacts using the email to find the contact record and that works fine. It pulls up the entire record for that contact… how ever all i need is the 4 digit id of the cient. Is there a way to modify my search command to only pull up the id or am i stuck with wasting the time to pull up the entire record and parse out the id…

In item 1 above you can see it id=1791 right at the beginning… so i could parse that out pretty quick since there will never be but i contact… but i would like to only load the id if possible.

Item 2 shows the actual record id… far down maybe 20,000 bytes deep… but surely i can mod my search to once it finds the record only bring home the id… Is that possible… Thanks.

IF anyone has ideas of another way to complete this task here is what i am trying to achieve…

  1. Use api to send new contact to the mautic data base…
  2. immediately follow the contact insertion with a request for his/her id so that i can follow with the command to assign that new lead to a specific segment to start a campaign.
  3. Of course i need the segemnt id, which i have along with the contact id to be able to use the Api to add the new contact to the segment… Thoughts or ideas for a better way…???
    Too bad we cannot assign a lead to a segment via his email as that would kill 2 birds with one stone…

Hi,

As you can see from this method here: < https://github.com/mautic/api-library/blob/9087ddec6400eb0c8aa43859eb7710cc9948c1ce/lib/Api/Contacts.php#L84 >, you have a parameter named “$minimal”, maybe that would return less data and because of it, everything… should go faster.

Does not mautic api return contact id on contact creation/insertion?

And for 3.) As I can see from mautic api library you can specify to add more leads to one segment at once - maybe you can use that to you advantage by grouping all ids into different groups within your integration script and then call the method here: < https://github.com/mautic/api-library/blob/9087ddec6400eb0c8aa43859eb7710cc9948c1ce/lib/Api/Segments.php#L63 >, to all contacts to specific segments at once.

It goes without saying, but if you still think you cant use any of the above to your advantage you can always register custom api endpoint via Mautic plugin

Thanks for that Mgaz, but i don’t know how to use all that… I am doing something very simple to get the contact like:
mymautic.com/api/contacts/search=‘theemailofthelead@something.com’
and since the email is unique it will pull up the correct contact along with 5 miles of other shit on the contact… but i only need the id of the contact… so i have to load the entire data and parse if for the id… Works great but so inefficient… and wastefull of processing…

Wish i did know how to use all that you pointed out as it looks like it might work… Thanks again… for your suggestion.

Try something like:

https://mymautic.com/api/contacts/?search=email:info@example.com&minimal=1

The docs says that it returns entities without additional lists in it, but as I see it there is still a lot of data - more that you would expect.