Answers.Body: <p>I don't think that is possible. The chained API works to extend the data on the contacts found.</p>
  
  <p>Could you explain a little more on why and what you want to achieve functional?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-17T15:43:00.530Z
Answers.Text: 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.
Answers.UserDisplayName: joost
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-18T10:34:52.493Z
Answers.Text: 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)`
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-18T11:09:13.823Z
Answers.Text: That's what I eventually did, but it would have been nicer if the API was able to do that
Answers.UserDisplayName: joost
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-19T12:15:02.863Z
Answers.Text: Maybe you can write down how you solved it in your question. So others could learn from it.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-17T13:02:42.843Z
Answers.LastActivityDate: 2018-01-17T13:02:42.843Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.Body: <p>I feel it's not possible to do such complicated filtering in api. You will need to add php code with multiple api calls</p>
  
  <ol>
  <li>Get all the contacts using address api with location type = billing.</li>
  <li>Use Contact get api to retrieve all contacts using condition id NOT in contact id's retrieved from #1</li>
  </ol>
  
  <p>HTH</p>
  
  <p>Pradeep </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-17T13:45:02.727Z
Answers.LastActivityDate: 2018-01-17T13:45:02.727Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>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?</p>
  
  <p>This is a non-working example of what I am trying to do.</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
    'sequential' =&gt; 1,
    'api.Address.get' =&gt; array('location_type_id' =&gt; "billing"),
    'api.Contact.get.count' =&gt; 0,
  ));
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-05T06:49:51.007Z
Comments.Text: Have you tried with API4?
Comments.UserDisplayName: ErikH - CiviCooP
Tags: <api><php><chaining>
Title: condition on count from chained api call
ThreadText: # condition on count from chained api call
  
  (Asked by: username_0 on 2018-01-17)
  
  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,
  ));
  
  **Tags:** api, php, chaining
  
  > **Comments:**
  > **username_1**: Have you tried with API4?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-01-17. Score: 1
  
  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?
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_2**: 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)`  
  > **username_0**: That's what I eventually did, but it would have been nicer if the API was able to do that  
  > **username_2**: Maybe you can write down how you solved it in your question. So others could learn from it.  
  
  ---
  
  ### Answer by username_3 on 2018-01-17. Score: 0
  
  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
  
  HTH
  
  Pradeep
  
  
  ---
  
  