2

How can I delete all CiviCRM Campaigns without having to delete one at a time? I have over 500 of them. Is there a way to do this with the API explorer?

5

Yes, you can do that with chaining in API Explorer:

enter image description here

$result = civicrm_api3('Campaign', 'get', [
  'sequential' => 1,
  'options' => ['limit' => 0],
  'api.Campaign.delete' => ['id' => "\$value.id"],
]);
2

The API Explorer will only delete one at a time, unfortunately.

If you have command-line access, cv is a nice way to access the API to do this. You can run a command line: cv api Campaign.delete id=1.

Sometimes if I'm feeling lazy and I don't want to code something to mass delete, I'll do the following:

  • Open a spreadsheet program.
  • In column A, start filling in numbers: 1, 2, 3.
  • Select those cells and then drag. LibreOffice Calc, Google Sheets and Excel all know that you want to continue the series. Continue until you have however many rows you need (in your case, over 500).
  • In Cell B1, put the following formula:
="cv api Campaign.delete id=" & A1
  • Copy/paste that down all of column B. The end result is that you'll have 500+ lines that will each delete a single campaign.
  • Copy Column B, then paste it into a command line terminal.
  • Brilliant! Worked perfectly. In my case I used drush cvapi because cv api didn't work. but I did the whole spreadsheet thing and worked amazing. Thanks! – Yossi Sep 25 at 4:09

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.