0

I woudl like to mass delete contacts in my civicrm. I could search and delete using the GUI but it woudl take ages as there are so many.

I feel like I might be able to do this via the api?

Also another response suggested using views Bulk Delete of Spam Contacts and related Drupal Users

Does anyone have any tips?

I will have another question depending on the tips probably!

2
  • what is it about using the UI that would make it so slow?
    – petednz - fuzion
    Commented Dec 1, 2020 at 18:18
  • You might get better answers if you provide some more background, i.e why you want to mass delete contacts.
    – Alan Dixon
    Commented Dec 2, 2020 at 16:08

2 Answers 2

0

Potentially you could do this in a little script using the API?

3
  • Now for the stupid question. I have the abulity to go into support/developer/api3 [api 4 doesn't seem to be there and in the extension page it just says "obsolete"] and I can delete one contact but the only operator avilable to me with contact ID is = I was hoping I could use greater than but that doesnt seem to be an option. Can I run this script outside of my website? eg using ssh?
    – Caroline B
    Commented Dec 1, 2020 at 10:35
  • No, the delete API requires the ID. You can not mass delete directly, you will first have to retrieve the IDs of the ones you want to delete. That is why I recommended a little PHP job (as a scheduled job) but that needs some development skills. If you do not want to do that or can not, I would recommend the UI.... Commented Dec 1, 2020 at 12:46
  • Thanks Erik that's very helpful to know.
    – Caroline B
    Commented Dec 1, 2020 at 13:54
0

In APIv3 you delete one contact at at time using id = .... In APIv4 you can delete based on more flexible conditions.

You can get to both versions from Support > Developer > API Explorer 3 or 4. If that is not showing up, what version are you on?

You can run it as a script via ssh. Both API Explorers show you the equivalent php code. Copy that into a file then you can run it with cv scr /your/script/file.

Alternatively, Explorer also shows you a cv version section (APIv3) or CLI (APIv4). Quoting can get awkward for anything complex directly on the command line.

4
  • I think I might need to work out where my API v 4 went (it was there but complained that it needed bootstrap and shoreditch which I installed which is when it dissappeared). I think once I have resolved that I may be back here. But the other question you have answered which I wasn't sure of was where to put the script - now I understand. In case you are feeling frightened on my behalf - this is a development instance of an existing site. I'm deleting all the contacts from it. So even if I screw up it's not going to be disastrous! Thanks Aidan!
    – Caroline B
    Commented Dec 1, 2020 at 13:57
  • APIv4 was originally an extension but it is now part of core. So it depends what version you are using as to what you need to do to get it working. The upgrades should take care of the change but if not, go your extensions page and disable and uninstall APIv4 if it is there. If that doesn't fix it create a separate question. And good that this is a development box :-)
    – Aidan
    Commented Dec 1, 2020 at 17:11
  • Thanks for that Aidan - my civi is 5.26.2. so i think fairly up to date. The APIv4 extension doesn't have a disable button - it just says obselete. But I know have APIv4 working through the support menu item so I don't think the old extension is getting in the way. Thanks
    – Caroline B
    Commented Dec 3, 2020 at 17:42
  • For anyone else trying to do this I found this very useful video that helped flesh out the answers above youtube.com/watch?v=-vy62VwKm9E
    – Caroline B
    Commented Feb 2, 2021 at 11:21

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.