Answers.Body: <p>If you're on Drupal and have drush installed you can do</p>
  
  <pre><code>drush cvapi Contact.delete id=17 skip_undelete=1
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-27T19:07:30.300Z
Answers.LastActivityDate: 2015-09-28T08:04:07.827Z
Answers.LastEditDate: 2015-09-28T08:04:07.827Z
Answers.UserDisplayName: DaveFF
Answers.Body: <p>On the command line, type <code>php path/to/civicrm/bin/cli.php -e Contact -a delete --output --contact_id=17</code> (Note: passing a contact_id is mandatory when deleting. But you can delete multiple contacts by creating a php file that has a loop and executes the above command through exec().)</p>
  
  <p>If you want to permanently delete a contact, add the skip_undelete parameter as well: <code>php path/to/civicrm/bin/cli.php -e Contact -a delete --output --contact_id=17 --skip_undelete=true</code></p>
  
  <p>I was, however, having problems with permanent deleting. I was just getting the error <code>Could not delete contact</code>. Looking at the code, my suspicion proved right - it was a permissions issue. So I tried to pass my admin CMS user login credentials: <code>php path/to/civicrm/bin/cli.php -e Contact -a delete -u myuser -p mypass --output --contact_id=17 --skip_undelete=true</code>. Unfortunately, for some reason it didn't work for me. Anyways, I thought I'd share my experiences - maybe I'm missing something or it might work for someone else. To circumvent this, in my case I just temporarily commented out the permissions check in CRM_Contact_BAO_Contact->deleteContact().</p>
  
  <p>Tip: because the delete isn't very fast, if you are deleting a large number of contacts it might take quite a while to go through them. The little trick I used to speed this up was to start multiple instances of my shell and have each of them delete a portion of my contacts. In that case I found it more convenient to use a bash for loop, like so: <code>for i in {50000..100000}; do php cli.php -e Contact -a delete --output --contact_id=$i --skip_undelete=true; echo Deleted contact_id $i; done</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-27T18:44:48.987Z
Answers.LastActivityDate: 2015-09-28T20:54:30.137Z
Answers.LastEditDate: 2015-09-28T20:54:30.137Z
Answers.UserDisplayName: Borislav Zlatanov
Body: <p>How can I delete a contact through the command line?</p>
  
Tags: <api><contacts><cli>
Title: How to delete a contact through the command line (CLI)
ThreadText: # How to delete a contact through the command line (CLI)
  
  (Asked by: username_0 on 2015-09-27)
  
  How can I delete a contact through the command line?
  
  **Tags:** api, contacts, cli
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-09-27. Score: 5
  
  If you're on Drupal and have drush installed you can do
  
  ```
  drush cvapi Contact.delete id=17 skip_undelete=1
  
  ```
  
  
  ---
  
  ### Answer by username_0 on 2015-09-27. Score: 4
  
  On the command line, type `php path/to/civicrm/bin/cli.php -e Contact -a delete --output --contact_id=17` (Note: passing a contact\_id is mandatory when deleting. But you can delete multiple contacts by creating a php file that has a loop and executes the above command through exec().)
  
  If you want to permanently delete a contact, add the skip\_undelete parameter as well: `php path/to/civicrm/bin/cli.php -e Contact -a delete --output --contact_id=17 --skip_undelete=true`
  
  I was, however, having problems with permanent deleting. I was just getting the error `Could not delete contact`. Looking at the code, my suspicion proved right - it was a permissions issue. So I tried to pass my admin CMS user login credentials: `php path/to/civicrm/bin/cli.php -e Contact -a delete -u myuser -p mypass --output --contact_id=17 --skip_undelete=true`. Unfortunately, for some reason it didn't work for me. Anyways, I thought I'd share my experiences - maybe I'm missing something or it might work for someone else. To circumvent this, in my case I just temporarily commented out the permissions check in CRM\_Contact\_BAO\_Contact->deleteContact().
  
  Tip: because the delete isn't very fast, if you are deleting a large number of contacts it might take quite a while to go through them. The little trick I used to speed this up was to start multiple instances of my shell and have each of them delete a portion of my contacts. In that case I found it more convenient to use a bash for loop, like so: `for i in {50000..100000}; do php cli.php -e Contact -a delete --output --contact_id=$i --skip_undelete=true; echo Deleted contact_id $i; done`
  
  
  ---
  
  