Answers.Body: <p>You can pass the <code>skip_undelete</code> parameter to the API, ie.</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'delete', array(
    'sequential' =&gt; 1,
    'id' =&gt; 9999999999999999999, // replace with your contact's Id.
    'skip_undelete' =&gt; 1,
  ));
  </code></pre>
  
  <p>Obviously a lot of care has to be taken over specifying the id to delete...</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-11T12:14:54.927Z
Answers.Text: Hmmm. However when I try to run this in my CLI test code it says "could not delete contact". Separate question or quick comment reply?
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-11T12:38:40.563Z
Answers.Text: CiviCRM on Drupal uses Drupal's user_access() for checking permissions; `global $user; $user = user_load(1);` does the trick if you can't use `drush -u 1 scr <yourscript>` for some reason.
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-19T14:19:51.603Z
Answers.Text: Thanks, that worked.
Answers.UserDisplayName: Hassan Farooq
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-10T12:00:26.923Z
Answers.LastActivityDate: 2015-12-10T12:00:26.923Z
Answers.UserDisplayName: artfulrobot
Body: <p>I'm creating an automated test script. It creates a test contact, does some stuff, then cleans up after itself by deleting the contact.</p>
  
  <p>However this still leaves the contact in the "Trash".</p>
  
  <p>How can I either just delete the contact fully with one API call?</p>
  
Tags: <api><4.6>
Title: How to permanently delete contact with API?
ThreadText: # How to permanently delete contact with API?
  
  (Asked by: username_0 on 2015-12-10)
  
  I'm creating an automated test script. It creates a test contact, does some stuff, then cleans up after itself by deleting the contact.
  
  However this still leaves the contact in the "Trash".
  
  How can I either just delete the contact fully with one API call?
  
  **Tags:** api, 4.6
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-12-10. Score: 12 | Accepted answer
  
  You can pass the skip_undelete parameter to the API, ie.
  $result = civicrm_api3('Contact', 'delete', array(
    'sequential' => 1,
    'id' => 9999999999999999999, // replace with your contact's Id.
    'skip_undelete' => 1,
  ));
  
  Obviously a lot of care has to be taken over specifying the id to delete...
  
  > **Comments:**
  > **username_0**: Hmmm. However when I try to run this in my CLI test code it says "could not delete contact". Separate question or quick comment reply?  
  > **username_0**: CiviCRM on Drupal uses Drupal's user_access() for checking permissions; `global $user; $user = user_load(1);` does the trick if you can't use `drush -u 1 scr <yourscript>` for some reason.  
  > **username_1**: Thanks, that worked.  
  
  ---
  
  