agilecrm / php-api

PHP Client to Access Agile Functionality
25 stars 33 forks source link

Update contact if already exists #13

Closed cscheltinga closed 7 years ago

cscheltinga commented 7 years ago

When trying to add a contact using: curl_wrap("contacts", $contact_json, "POST", "application/json") it works great. But if the contact already exists; nothing happens.

You'd like to be able to update contact if it exists, or else create new contact.

graut commented 7 years ago

Hi @cscheltinga ,

Above API only for creating contact. If you have same email present all ready then you will get duplicate error.

You can follow below step.

  1. Get contact by ID or email

reference - https://github.com/agilecrm/php-api#12-to-fetch-contact-data

  1. If no contact found create new contact

reference - https://github.com/agilecrm/php-api#11-to-create-a-contact

  1. If contact found update it

reference - https://github.com/agilecrm/php-api#14-update-properties-of-a-contact-partial-update

Note : Currently we don't have API which will create and update contact at same time.

cscheltinga commented 7 years ago

That's what I just created, thnx! Would be nice to have on call to create/update at once though :-)