I am trying to use the api to get all contacts without an address with locationtype billing. For this I use the contact get api, and do a chained address get call. Is there a way to put a condition on the number of results from the chained call?

This is a non-working example of what I am trying to do.

$result = civicrm_api3('Contact', 'get', array(
  'sequential' => 1,
  'api.Address.get' => array('location_type_id' => "billing"),
  'api.Contact.get.count' => 0,

2 Answers 2


I don't think that is possible. The chained API works to extend the data on the contacts found.

Could you explain a little more on why and what you want to achieve functional?

  • we have a couple addresses for each of our teams. When there is an address of the type billing we use that one as the billing address, but if that one doesn't exist we use an other one. I was looking for a way to set the is_billing flag on those addresses for the contacts with no billing address available.
    – joost
    Jan 17, 2018 at 15:43
  • 1
    You can probably do that with some SQL. Below an example of how such a query works. You have probably to adjust the location_type field and probably rebuild it to an update query. Select * from civicrm_address where location_type != billing and contact_id NOT in (select contact_id from civicrmadress where location_type = billing) Jan 18, 2018 at 10:34
  • That's what I eventually did, but it would have been nicer if the API was able to do that
    – joost
    Jan 18, 2018 at 11:09
  • 1
    Maybe you can write down how you solved it in your question. So others could learn from it. Jan 19, 2018 at 12:15

I feel it's not possible to do such complicated filtering in api. You will need to add php code with multiple api calls

  1. Get all the contacts using address api with location type = billing.
  2. Use Contact get api to retrieve all contacts using condition id NOT in contact id's retrieved from #1



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.