- // add contact using dedupe rule
- $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
- $dedupeParams['check_permission'] = FALSE;
- $dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
- // if we find more than one contact, use the first one
- if (!empty($dupeIds[0])) {
- $params['contact_id'] = $dupeIds[0];
- }
- $contact = CRM_Contact_BAO_Contact::create($params);
- if (!$contact->id) {
- return FALSE;
- }
+ $params['contact_id'] = CRM_Contact_BAO_Contact::getFirstDuplicateContact($params, 'Individual', 'Unsupervised', array(), FALSE);
+
+ $contact = civicrm_api3('Contact', 'create', $params);