API 'match' => "external_identifier"
You need to implement something like below

$result = civicrm_api3('Contact', 'create', [
  'first_name' =&gt; "first name",
  'last_name' =&gt; "last name",
  'email' =&gt; "pradeep@test.com",
  'external_identifier' =&gt; "S-123456",
  'options' =&gt; ['match' =&gt; "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