Q:

API 'match' => "external_identifier"

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

A:

You need to implement something like below
$result = civicrm_api3('Contact', 'create', [
  'first_name' => "first name",
  'last_name' => "last name",
  'email' => "pradeep@test.com",
  '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.
HTH
Pradeep

