Answers.Body: <p>Api4 will likely to be able to do this, but it is not yet released.
  It is not possible with api3. You'll need to write a custom php script to loop and call the api repeatedly, or else execute a sql query.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-26T18:46:47.920Z
Answers.LastActivityDate: 2016-09-26T18:46:47.920Z
Answers.UserDisplayName: Coleman
Body: <p>In development I would like to use the API to delete all contacted except conctact_id  1 and 2. With Contact</p>
  
  <p>This:</p>
  
  <pre><code>$result=civicrm_api3('Contact', 'delete', array(
        'id' =&gt; array('NOT IN' =&gt; array(1, 2)),
        'skip_undelete' =&gt; "1",
      ));
  </code></pre>
  
  <p>.. won't work even though with get it does. Would seem there is no good way to do this fast, without making a complicated MySQL query. Who knows a quick work around. Mine were extremely slow and ran into error 500 timeout errors. </p>
  
Tags: <contacts><api><developer>
Title: How to use API to bulk delete contacts quickly?
ThreadText: # How to use API to bulk delete contacts quickly?
  
  (Asked by: username_0 on 2016-09-22)
  
  In development I would like to use the API to delete all contacted except conctact_id  1 and 2. With Contact
  This:
  $result=civicrm_api3('Contact', 'delete', array(
        'id' => array('NOT IN' => array(1, 2)),
        'skip_undelete' => "1",
      ));
  
  .. won't work even though with get it does. Would seem there is no good way to do this fast, without making a complicated MySQL query. Who knows a quick work around. Mine were extremely slow and ran into error 500 timeout errors.
  
  **Tags:** contacts, api, developer
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-26. Score: 1 | Accepted answer
  
  Api4 will likely to be able to do this, but it is not yet released.
  It is not possible with api3. You'll need to write a custom php script to loop and call the api repeatedly, or else execute a sql query.
  
  
  ---
  
  