Zendesk Script – Delete all organizations

No Comments

So, this is going to be my first post of 2015. I haven’t had time for anything since holidays but now I have some free time to provide you the latest script.

You know those moments were you are kind of… SCREW EVERYTHING!!! I’m going to start over! Well, one of the steps you will need to do in your Zendesk account at some point is to delete all the organizations. To do so, you just have to use this simple script:

var v_subdomain = "SUBDOMAIN";
var v_orgs_amount = ORGAMOUNTS;

function getOrgs(page) {

        url: "https://" + v_subdomain + ".zendesk.com/api/v2/organizations.json?page=" + page,
        type: "GET",
        dataType: "JSON"
    }).done(function(data) {
        for (var i = 0; i < data.organizations.length; i++) {
            var orgid = data.organizations[i].id;

function deleteOrg(orgID) {
    setTimeout(function() {
            url: "https://" + v_subdomain + ".zendesk.com/api/v2/organizations/" + orgID + ".json",
            type: "DELETE",
            dataType: "JSON"
        }).done(function(data) {
            console.log("Organization " + orgID + " Deleted");
        }).fail(function(data) {
            console.log("Can't delete organization ID " + orgID);
    }, 5000);

for (var j = 0; j < Math.ceil(v_orgs_amount / 100); j++) {
    getOrgs(j + 1);

As always you will just need to fill your v_subdomain and the amount of organizations you have. Open the Chrome console while you are logged in your Zendesk account, paste the code and run it! :)

I’ve tried to add some waiting time on the AJAX call to avoid reaching the API limits in case you have a lot of Organizations but I think I did it wrong. May you reach the limit, wait a few and run it again. (Make sure you change the amount of Orgs since you have already deleted some). I’ll investigate a bit more and I will update all the scripts once I find out the best solution for it.

Remember that as always you can see the latest code in my GitHub profile and that…