Is it possible to Contact.get where civicrm_id = external_identifier, using API?
If you want to stay with the API you can filter in php:

$result = civicrm_api3('Contact', 'get', array(
  'sequential' =&gt; 1,
  'return' =&gt; array("id", "external_identifier"),
  'external_identifier' =&gt; array('IS NOT NULL' =&gt; 1),
  'options' =&gt; array('limit' =&gt; 0),
));
$ids = array();
foreach ($result['values'] as $contact) {
  if ($contact['id'] == $contact['external_identifier']) {
    $ids[] = $contact['id'];
  }
}
print_r($ids);