Skip to content

Instantly share code, notes, and snippets.

@ankitjaininfo
Created October 15, 2015 09:25
Show Gist options
  • Save ankitjaininfo/e57dc505de040d34b5c3 to your computer and use it in GitHub Desktop.
Save ankitjaininfo/e57dc505de040d34b5c3 to your computer and use it in GitHub Desktop.
Delete All Subaccounts in Mandrill (nodejs)
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);
});
@ankitjaininfo
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment