How can I retrieve all the phone numbers for a contact using the PHP object-oriented API? I'm only seeing the primary phone available in the API explorer. I want to be able to create a directory of everyone in a certain group, including all their phone numbers, with labels like "home", "work", "mobile".

My query currently looks like this:

             'group' => 6,
             'sequential' => 1,
             'rowCount' => 100,
             'return' => 'custom_4,display_name,email,phone,'.


1 Answer 1


If you look in CRM_Contact_BAO_Query, it looks like it takes the "location" return property into account when considering primary, but location is an array but using the api you'd have to somehow put it in the return string, so I'm not sure how you'd specify it.

If you're willing to stray a little from the official api, there is the less official CRM_Contact_BAO_Contact::retrieve(). So something like

$params = array('contact_id' => 4); // 4 is an example, use the desired contact id $defaults = array(); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults);

And then there's an array under $contact->phone

  • Cool - even better, once I have a Contact object in $c, it looks like I can just retrieve the Phone objects by doing $p = CRM_Core_BAO_Phone::allPhones($c->id). Thanks for the help! Commented Jul 26, 2016 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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