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 (Moderator: Donald Lobo) »
  • API3: contact, getsingle via email
Pages: [1]

Author Topic: API3: contact, getsingle via email  (Read 470 times)

sussdorff

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 4
  • CiviCRM version: 3.4
  • CMS version: Drupal 6
API3: contact, getsingle via email
August 15, 2011, 08:26:56 am
Hello,

I wanted to get a contact using his/her e-mail.

$partner=civicrm_api("Contact","getsingle", array ('version' =>'3', 'email' => $row['partner_email']));

So far the good, if only it would work with additional E-Mail Addresses. So it won't find a contact if $row['partner_email'] isn't the primary E-Mail.

What parameter am I misusing / missing here?

Best wishes
 Malte

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API3: contact, getsingle via email
August 15, 2011, 08:52:25 am
Hi,

Contact.getsingle works only with primary emails.

What you want to do is to api chain mail.getsingle and contact.getsingle.

(top of my head:

civicrm_api('email','getsingle',array(email=>$email,'api.contact.getsingle'=>array(id="$values.contact_id")))

http://wiki.civicrm.org/confluence/display/CRMDOC40/Chaining
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

sussdorff

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 4
  • CiviCRM version: 3.4
  • CMS version: Drupal 6
Re: API3: contact, getsingle via email
August 15, 2011, 09:07:21 am
Thanks Xavier, I need to look into chaining in the future.

For the time being I solved it this way, which pretty much follows your notion of having to use Email instead of Contact. Additionally I found out that you get in trouble if an E-mail is linked with multiple contacts as the contacts have been marked as deleted but haven't been deleted for good.

$partner=civicrm_api("Contact","getsingle", array ('version' =>'3', 'email' => $row['dance_partner_email']));
$partner_contact_id = 0;
if($partner['is_error'] == 0) {
   $partner_contact_id = $partner['contact_id'];
} else {
   // check if we have the E-Mail elsewhere
   $partner_emails=civicrm_api("Email","get", array ('version' =>'3', 'email' => $row['dance_partner_email']));
   if($partner_emails['is_error'] == 0) {
           $partner_email = end($partner_emails['values']);
           $partner_contact_id = $partner_email['contact_id'];
      $partner=civicrm_api("Contact","getsingle", array ('version' =>'3', 'contact_id' => $partner_contact_id));
   }
}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • API3: contact, getsingle via email

This forum was archived on 2017-11-26.