Last active
August 29, 2015 13:58
-
-
Save shaundon/10404109 to your computer and use it in GitHub Desktop.
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
/* | |
Call start() on console to run program. | |
May be a little rough around the edges, I'm trying to remember the | |
jQuery API from memory as my home internet's too slow to Google stuff. | |
Oh and it requires jQuery, because everything requires jQuery! | |
*/ | |
function start() { | |
// Ask the API for campaigns. | |
$.ajax({ | |
method: 'GET', | |
url: '/tm-api-ajax/campaign', | |
async: false, | |
success: function(campaigns) { | |
var idsToDelete = []; | |
// Go through each campaign. | |
$.each(campaign, function(index, campaign) { | |
// Store the ID. Note, this might be campaign.id instead of | |
// campaign.campaignId. Check with Sam. | |
idsToDelete.push(campaign.campaignId); | |
}); | |
// Do the deletion. | |
doDeletion(idsToDelete); | |
} | |
}); | |
} | |
function doDeletion(ids) { | |
$.each(ids, function(index, idToDelete) { | |
$.ajax({ | |
url: '/tm-api-ajax/campaign', | |
method: 'DELETE', | |
async: false, | |
params: { | |
id: idToDelete | |
}, | |
success: function() { | |
console.log(id + ' was deleted successfully'); | |
}, | |
error: function() { | |
console.log(id + ' was not deleted successfully'); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment