Answers.Body: <p>With API4 you can do it like this:</p>
  
  
  
  <pre><code>$contacts = \Civi\Api4\Contact::get()
    -&gt;addClause('OR',
       ['birth_date', '&lt;=', '1960-01-01'],
       ['birth_date', 'IS NULL']
      )
    -&gt;execute();
  foreach ($contacts as $contact) {
    // do something
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-13T14:00:38.997Z
Answers.LastActivityDate: 2020-01-13T14:00:38.997Z
Answers.UserDisplayName: artfulrobot
Answers.Body: <p>Barring some undocumented feature (which are rife in the API, so someone please correct me), I think you'll have to merge the two.  However, since you're dealing with "get" calls, it's straightforward to merge the two results.</p>
  
  <p>First, you'll want to get rid of the <code>sequential</code> parameter; without it, you'll get arrays of values keyed by ID.  Then, you'll have a pretty simple situation:</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
    'birth_date' =&gt; array('IS NULL' =&gt; 1),
  ));
  
  $result2 = civicrm_api3('Contact', 'get', array(
    'birth_date' =&gt; array('&lt;=' =&gt; "1960-01-01"),
  ));
  
  $combined = array_merge($result['values'], $result2['values']);
  </code></pre>
  
  <p>The result will have only one row per contact.  Although obviously there's no overlap between people with no birth date and people with birth dates prior to 1960, you could use the same principle for merging potentially overlapping groups since the array key is the ID.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T07:52:13.863Z
Answers.Text: Thank you for this clean solution. A problem with it is that you cannot use API-chaining. But it's not too hard to work around.
Answers.UserDisplayName: johanv
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-11T20:35:52.433Z
Answers.LastActivityDate: 2015-08-11T20:35:52.433Z
Answers.UserDisplayName: Andie Hunt
Body: <p>If I want to find all contacts without a birth date, I can do this with the api:</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
    'sequential' =&gt; 1,
    'birth_date' =&gt; array('IS NULL' =&gt; 1),
  ));
  </code></pre>
  
  <p>If I want to find all contacts with a birth date before a given date, it works like this:</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
    'sequential' =&gt; 1,
    'birth_date' =&gt; array('&lt;=' =&gt; "1960-01-01"),
  ));
  </code></pre>
  
  <p>Now suppose I want to both the contacts without a birth date and the contacts born before a particular date, can I do that in one API call?</p>
  
Tags: <api>
Title: How can I 'or' 2 conditions using the api?
ThreadText: # How can I 'or' 2 conditions using the api?
  
  (Asked by: username_0 on 2015-08-11)
  
  If I want to find all contacts without a birth date, I can do this with the api:
  
  ```
  $result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'birth_date' => array('IS NULL' => 1),
  ));
  
  ```
  
  If I want to find all contacts with a birth date before a given date, it works like this:
  
  ```
  $result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'birth_date' => array('<=' => "1960-01-01"),
  ));
  
  ```
  
  Now suppose I want to both the contacts without a birth date and the contacts born before a particular date, can I do that in one API call?
  
  **Tags:** api
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-08-11. Score: 5 | Accepted answer
  
  Barring some undocumented feature (which are rife in the API, so someone please correct me), I think you'll have to merge the two. However, since you're dealing with "get" calls, it's straightforward to merge the two results.
  
  First, you'll want to get rid of the `sequential` parameter; without it, you'll get arrays of values keyed by ID. Then, you'll have a pretty simple situation:
  
  ```
  $result = civicrm_api3('Contact', 'get', array(
    'birth_date' => array('IS NULL' => 1),
  ));
  
  $result2 = civicrm_api3('Contact', 'get', array(
    'birth_date' => array('<=' => "1960-01-01"),
  ));
  
  $combined = array_merge($result['values'], $result2['values']);
  
  ```
  
  The result will have only one row per contact. Although obviously there's no overlap between people with no birth date and people with birth dates prior to 1960, you could use the same principle for merging potentially overlapping groups since the array key is the ID.
  
  > **Comments:**
  > **username_0**: Thank you for this clean solution. A problem with it is that you cannot use API-chaining. But it's not too hard to work around.  
  
  ---
  
  ### Answer by username_1 on 2020-01-13. Score: 4
  
  With API4 you can do it like this:
  
  ```
  $contacts = \Civi\Api4\Contact::get()
    ->addClause('OR',
       ['birth_date', '<=', '1960-01-01'],
       ['birth_date', 'IS NULL']
      )
    ->execute();
  foreach ($contacts as $contact) {
    // do something
  }
  
  ```
  
  
  ---
  
  