CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Deleting trashed contacts with API call
Pages: [1]

Author Topic: Deleting trashed contacts with API call  (Read 1448 times)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Deleting trashed contacts with API call
September 23, 2012, 07:49:24 pm
Hi

I've deleted several thousand contacts on purpose with an API call.
To find the contacts I used this:
$results=civicrm_api("Contact","get", array ('version' => 3,'sequential' =>'1', 'contact_sub_type' =>'student', 'return.id' => 1, 'rowCount' => '39000'));

To delete them I ran the $results array through a foreach loop where I deleted them with:

$result_delete = civicrm_api("Contact", "delete", array ( 'version' => 3, 'sequential' =>'1', 'id' => $id  ) );

It worked good and was much faster than I thought - I had to run the script a couple of times though (?).

Anyways I now discover that contact delete used as above put's the contacts in the trash. So now I have 39000 contacts in trash that I want to delete permanently with an API call.

How do I do that? Using 'contact_is_deleted' => 1 to find them and 'skip_undelete' => 1 in the delete call doesn't work for me. Somebody mentions a 'showAll' parameter for some versions back - doesn't work for me either.

All help apreciated :)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Deleting trashed contacts with API call
September 24, 2012, 12:11:31 am
can you try this:
Code: [Select]
$results=civicrm_api("Contact","get", array (version => '3','sequential' =>'1', 'contact_is_deleted' =>'1'));for deleted ones?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Deleting trashed contacts with API call
September 24, 2012, 12:02:21 pm
It doesn't work for me:
$results=civicrm_api("Contact","get", array ('version' => '3','sequential' =>'1', 'contact_is_deleted' => '1', 'rowCount' => '39000'));
or
 $results=civicrm_api("Contact","get", array ('version' => '3','sequential' =>'1', 'contact_is_deleted' => '1'));
or
 $results=civicrm_api("Contact","get", array ('version' => '3','sequential' =>'1', 'contact_is_deleted' => 1));

They all return all my non-deleted contacts.
Even in the API
/civicrm/ajax/rest?json=1&debug=1&version=3&entity=Contact&action=get&contact_is_deleted=1
it returns all the non-deleted contacts. For fun I tryed contact_is_deleted=0 - that at least does as expected - anyways it seems like that parameter is ignored.


andyw

  • I post occasionally
  • **
  • Posts: 82
  • Karma: 4
  • CiviCRM version: 4.x
  • CMS version: Drupal, Joomla
Re: Deleting trashed contacts with API call
November 15, 2012, 09:41:24 am
Hi there,

I was having the same problem and came across this post - I know it's a couple of months old, but thought I'd add what I'd found, in case it helps anyone.

Not sure if you're using drush to do this at all, but if you are, it's probably failing on permissions.

It won't produce a helpful error message unfortunately - it'll just say 'Could not delete contact' in the api response, but the problem is drush runs, by default, as an anonymous user, which doesn't have permission to delete contacts.

Have tried adding --user=1 to the drush call, but that didn't seem to work either - so I've gone and patched the BAO function for deleting contacts for now so that it skips the permissions check when being called from drush.

Hope that's information someone might find useful, or if someone knows a better way to get round this, please let me know what that is.

Andy




Andrew Walker, Developer at Circle Interactive

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Deleting trashed contacts with API call
January 15, 2014, 02:22:55 pm
To directly delete a contact (no trash), use the 'skip_undelete' API param for your Contact delete call.

https://github.com/civicrm/civicrm-core/blob/master/api/v3/Contact.php#L247
@xurizaemon ● www.fuzion.co.nz

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Deleting trashed contacts with API call

This forum was archived on 2017-11-26.