6

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?

11

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? – artfulrobot Dec 11 '15 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. – artfulrobot Dec 11 '15 at 12:38
  • Thanks, that worked. – Hassan Farooq Apr 19 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.