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) »
  • How to get contacts by phone, address, website or email
Pages: [1]

Author Topic: How to get contacts by phone, address, website or email  (Read 701 times)

pminf

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.6
  • PHP version: 5.3
How to get contacts by phone, address, website or email
March 05, 2015, 04:02:34 am
I'm trying to get contacts which are related to a certain phone number, address, website or email id.

I've tried the following requests with no success:
Code: [Select]
$result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'api.Phone.get' => array('id' => "90")
 ));

Code: [Select]
$result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'phone_id' => 90
 ));

Code: [Select]
$result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'phone' => 90
 ));

The parameters regarding phone seem to be ignored and the result contains 25 contacts, which don't necessary have the phone_id 90.

Any idea how to accomplish this?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: How to get contacts by phone, address, website or email
March 05, 2015, 05:11:33 am
Weird, I thought the api.contact.get filters on phone.

One way/workaround is to fetch the phone first, then contacts. When you fetch contacts, it's good practice to specify what fields you want (return="first_name,last_name,...")
Code: [Select]
$result = civicrm_api3('Phone', 'get', array(
    id' => "90",
    'sequential' => 1,
    'api.Contact.get' => array('return' => "stuff n more")
 ));
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

pminf

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.6
  • PHP version: 5.3
Re: How to get contacts by phone, address, website or email
March 05, 2015, 05:53:45 am
Thanks for the workaround. I will give it a try and report back

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How to get contacts by phone, address, website or email
March 05, 2015, 06:13:24 am
I believe the contact api filters on phone number, not phone id. If you want to fetch phones/addresses/emails by their id, then X is correct you need to use the phone/address/email apis.
Try asking your question on the new CiviCRM help site.

pminf

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.6
  • PHP version: 5.3
Re: How to get contacts by phone, address, website or email
March 09, 2015, 01:50:18 am
Quote from: xavier on March 05, 2015, 05:11:33 am
Weird, I thought the api.contact.get filters on phone.

One way/workaround is to fetch the phone first, then contacts. When you fetch contacts, it's good practice to specify what fields you want (return="first_name,last_name,...")
Code: [Select]
$result = civicrm_api3('Phone', 'get', array(
    id' => "90",
    'sequential' => 1,
    'api.Contact.get' => array('return' => "stuff n more")
 ));

Same here: the result contains 25 "related" contacts, which don't necessary have the phone id 90

johanv

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 5
  • #chiro #geek #linux #beer
    • my homepage
  • CiviCRM version: 4.7.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.x
Re: How to get contacts by phone, address, website or email
March 10, 2015, 12:52:35 pm
You might want to try

Code: [Select]
$result = civicrm_api3('Phone', 'get', array(
    id' => "90",
    'sequential' => 1,
    'api.Contact.get' => array('id' => "\$value.contact_id"),
 ));

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to get contacts by phone, address, website or email

This forum was archived on 2017-11-26.