CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Email Address and Contact Create vs Get
Pages: [1]

Author Topic: Email Address and Contact Create vs Get  (Read 1373 times)

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Email Address and Contact Create vs Get
May 01, 2012, 03:38:19 pm
I'm slowly migrating our API to version 3 and have a couple of questions.

First, our uniqueness is First Name, Last Name, and Email.  Using Contact Create, when I set the "dedupe_check" parameter on, it properly errors out if it finds a person where those three fields match.  And, it checks for *any* email per contact to make the match.  So if we have a contact with a primary email address and a second one, Contact Create will error even if the second one matches and not the primary.

However, Contact Get does not do this.  It only returns records where the primary email address is found (if I include First, Last, and Email in my parameters).  Is there something I need to tell Contact Get in order to return results where any email matches what I send it?

The issue I have is we have to do a Get before a Create to see if a contact already exists.  The Get is saying it doesn't exist, but the Create then says there is a duplicate.

The second question, related to that, is when the Create finds a duplicate, it does not put the duplicate Contact ID(s) into it's own array.  I believe v2 of the API did that (it put it into a field called error_data, I believe).  Is there a reason we no longer have that?  It would be nice to just call Contact Create with dedupe_check on and, if it finds a dupe, get the ID and move on.  At this point, it seems we have to parse the error message and hope the text of it doesn't change down the road (not sure it would, but just afraid of doing that).  If the Get would return the results, we wouldn't need the dedupe_check, but since it's not, we're having to rely on this as well, I think.  Maybe there is another way?

Thanks.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Email Address and Contact Create vs Get
May 02, 2012, 02:37:20 am
Hi,

there is an option to check duplicates when creating a contact

civicrm_api (... array (... 'dupe_check'=>true
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Email Address and Contact Create vs Get
May 02, 2012, 03:45:22 am
Hi,
Yes, I actually use that option.  However, per my question, it doesn't behave the same way as Contact Get.  The two functions are not consistent when it comes to secondary email addresses.  And, using dupe_check no longer provides the already existing Contact ID as a separate field in it's results (see my original post for details of what I mean).  Those are two issues for me as we migrate.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Email Address and Contact Create vs Get
May 02, 2012, 04:00:25 am
Hi,

api/v3/Contact.php line 390
    $ids = implode(',', CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type'], 'Strict', array(), $dedupeRuleGroupID));

Would be good if you could investigate, seems that it's using the standard dedupe (strict)

Agree with that the parsing of error message not being super robust. That needs to be improved

line 397
you could fix by assigning an array with extra error info as the 2nd array

extra = array ("error_type" => "duplicate", duplicate_id => $ids);

Could you try and catch us  on IRC if you need a hand?

X+

civicrm_api3_create_error

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Email Address and Contact Create vs Get
May 02, 2012, 04:53:59 am
Great, thanks much for the pointer!  It looks like all I needed to modify was api/v3/Contact.php using that extra array.  I have it returning an array of the duplicate ids (figured it's a little nicer than the comma-separated string).  Thanks much, this will help a lot!

Here are my changes if it helps others (I'll also create an issue in JIRA referencing this).  Starting at line 381:

Code: [Select]
        if ( $ids != null ) {
            // Add error type and the set of duplicate IDs into the resulting error array
            $extra_error_info = array("error_type" => "duplicate", "duplicate_ids" => explode(',', $ids));
            if ( $dupeErrorArray ) {
                $error = CRM_Core_Error::createError( "Found matching contacts: $ids",
                                                      CRM_Core_Error::DUPLICATE_CONTACT,
                                                      'Fatal', $ids );
                return civicrm_api3_create_error( $error->pop( ), $extra_error_info );
            }
           
            $duplicate_ids = explode($ids, ',');
            return civicrm_api3_create_error( "Found matching contacts: $ids", $extra_error_info );
        }

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Email Address and Contact Create vs Get
May 02, 2012, 05:49:42 am
Hi,

Could you attach a patch to your issue & assign it to me? Would be cool you do it quickly so we can still put it for 4.2

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

pbarmak

  • I post occasionally
  • **
  • Posts: 111
  • Karma: 3
  • CiviCRM version: 3.3.5
  • CMS version: Pressflow 6.19
  • MySQL version: 5.1
  • PHP version: 5.2.10
Re: Email Address and Contact Create vs Get
May 02, 2012, 05:55:38 am
Patch is here: http://issues.civicrm.org/jira/browse/CRM-10152

I couldn't figure out how to assign it to you (not sure if I have permission).

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Email Address and Contact Create vs Get

This forum was archived on 2017-11-26.