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?

1 Answer 1


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...

  • 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? Dec 11, 2015 at 12:14
  • 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. Dec 11, 2015 at 12:38
  • Thanks, that worked. Apr 19, 2019 at 14:19

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.