Dupcheck for more than email with Rest

I’m using the Rest PHP SDK, and have been successful in adding Contacts and updating Contacts when their email matches. I’m using this call…

$result = $infusionsoft->contacts()->create($contact, true);

But I also need to be able to update the account if the email address has been entered incorrectly. I have been able to update contacts with the XML portion by first searching for a Contact’s id and then updating like this…

$returnResult = $infusionsoft->data->query(‘Contact’, 10, 0, [‘_MemberNumber’ => $memberNumber], [ ‘ID’], ‘Email’, true);

$id = $returnResult[0][‘ID’];

$result = $infusionsoft->contacts()->create([ ‘id’ => $id, ‘custom_fields’ => $newCustom, ‘email_addresses’ => [$email1], “opt_in_reason” => “Paid Member”]);

Is there not a simple way to use the Rest Create option and look for more than a duplicate email address?
Thanks!

Hey @Chris_Rosenberry, based on what I see here, you are querying to get a contact id based on a response from a query where you supply the MemberNumber? I’m afraid I can’t think of a good/quick way to query for this using REST without handling some of the processing in your code. What I mean by this is, we have a method to return contacts with custom fields. From the result of this method you would then need to search the data for your matching MemberNumber. I know this is not glamorous but it is the only solution that comes to mind using what we currently have available in REST.

Best,
Carlos

Thanks Carlos! So really, I just need to use my second block of code to do this…

Check for a matching Member Number (custom field) and if it exists run an update matching the returned ID.

Yes?

That is correct, the only problem with doing it this way is the time it takes to check against a large amount of contacts (if you have a large contact database) every time a new contact is added.

If you just need a retro-active solution and not a realtime solution, I would recommend looking into REST hooks, this will allow you to “subscribe” to, lets say a “contact added” event. Once you are subscribed to an event, you will receive a POST at your listening server that contains the newly created contact id. From there, you can update the info accordingly.