1

I want to get all contacts who have "CiviCRM Id = External Id"

This API call doesn't work because, id is expecting a numeric value

$result = civicrm_api3('Contact', 'get', array(
  'sequential' => 1,
   'id' => "external_identifier",
));

Any way to accomplish this using API?

  • This basically was a generic question (with a specific example) about if the API is able to use another Entitiy's fields as part of condition, rather than constant values. Looks like is not possible.. maybe with API v4.0 ?! – luciano_s Jul 26 '18 at 9:19
2

If you want to stay with the API you can filter in php:

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

Will this possible in API? - I am not sure

But

A simple SQL should be quicker - if you have access to Database

Else:

you can get a list quicker using CiviCRM Report

Reports -> Contact Report -> Constituent Summary

select column: contact ID and External ID to be displayed

Export into a CSV and then make a compare in csv

I guess this helps !!!!

0

It's not directly possible in the manner you indicate.

You would need to get a list of all contact's external IDs then loop through using the API to return contacts who's ID matches their external ID. The direct SQL route or report route given by @Ramesh would be quicker for a one-off task.

0

If you are familiair with SQL I would use a custom query for that. What exactly do you want to do with the result?

0

It's very simple and faster to get the result using sql query. You can try using chain api but i am not if it will filter out the result.

  $params = [
    'api.contact.get' => ['external_identifier' => '$value.id'],
    'return' => 'api.contact.get'
  ];
  $result = civicrm_api3('Contact', 'get', $params);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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