I am writing a script that updates contacts from an external source when their external identifier is equal to the contact being imported. My research shows (and the API explorer confirms) that it should look like this:

'options' => ['match' => "external_identifier"],

I get the error "CiviCRM_API3_Exception: Ambiguous match criteria in civicrm_api3() (line 45 of /var/www/html/sites/all/modules/civicrm/api/api.php)."

Can anyone suggest a solution for what I am doing wrong?

Thanks, Josh

1 Answer 1


You need to implement something like below

$result = civicrm_api3('Contact', 'create', [
  'first_name' => "first name",
  'last_name' => "last name",
  'email' => "[email protected]",
  'external_identifier' => "S-123456",
  'options' => ['match' => "external_identifier"],

Make sure you pass external_identifier in api params.

So basically above code snippet will first check if external_identifier "S-123456" is present in database and get its id if present and update the contact, if not present then new contact will be created.



  • Ya, that is what I am doing and I get "CiviCRM_API3_Exception: Ambiguous match criteria in civicrm_api3() (line 45 of /var/www/html/sites/all/modules/civicrm/api/api.php)." This is a shortened version of what my API call looks like $result = civicrm_api3('Contact', 'create', [ 'contact_type' => 'Individual', 'contact_sub_type' => 'Student', 'last_name' => $student_last_name, 'first_name' => $student_first_name, 'external_identifier' => $student_id, 'options' => ['match' => "external_identifier"], ]); Thanks!
    – Josh
    Jan 11, 2019 at 21:58
  • It means it's matching on more than one. Since there's a unique db index on that field my guess is you're passing a null $student_id ?
    – Demerit
    Jan 11, 2019 at 22:06
  • CiviCRM_API3_Exception: Ambiguous match criteria usually occurs when the match criteria field is passed with null value or empty. In your case $student_last_name must be null or empty hence the api throughs error. Jan 11, 2019 at 23:44
  • But the only match criteria is the external id, right? What all must be included to be a match? There could be some new students in the CSV.
    – Josh
    Jan 12, 2019 at 3:29
  • 1
    Change the options line to 'options' => ($student_id ? ['match' => "external_identifier"] : []),. In other words, don't pass in the match option if student_id is blank.
    – Demerit
    Jan 12, 2019 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.