Created
October 15, 2015 09:25
-
-
Save ankitjaininfo/e57dc505de040d34b5c3 to your computer and use it in GitHub Desktop.
Delete All Subaccounts in Mandrill (nodejs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mandrill = require('mandrill-api/mandrill'); | |
var async = require('async'); | |
mandrill_client = new mandrill.Mandrill('<place your key here>'); | |
var q = ""; | |
mandrill_client.subaccounts.list({ | |
"q": q | |
}, function (result) { | |
console.log("Found: ", result.length); | |
result.map(function (account) { | |
//console.log("Account: " + account.id + " >> " + account.name); | |
}); | |
/* Following code deletes that sub-account: Commented to prevent accidental delete | |
async.eachLimit(result, 10, function (account, callback) { | |
console.log("Tenant name:", account.name); | |
mandrill_client.subaccounts.delete({ | |
"id": account.id | |
}, function (deleteResult) { | |
callback(); | |
}, function (deleteErr) { | |
console.log('A mandrill error occurred: ' + deleteErr.name + ' - ' + deleteErr.message, deleteErr); | |
callback(); | |
}); | |
}, function (err) { | |
console.log("All done - " + result.length + " - " + err); | |
}) | |
*/ | |
}, function (e) { | |
// Mandrill returns the error as an object with name and message keys | |
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refer https://mandrillapp.com/api/docs/subaccounts.JSON.html#method=delete for more details