I work in advertising. I am using the FB graph API to 'DELETE' ad assignments from the platform for a client using the HTTP DELETE method.
My requests are in the format:
https://graph.facebook.com/v2.5/{{NODE_ID}}/{{EDGE_NAME}}?field_ids=['123456']
I normally use the graph explorer tool (https://developers.facebook.com/tools/explorer) to accomplish such a task, but the client has provided over 8000 assignment to delete so doing it manually one by one would be tough.
How can I invoke an HTTP DELETE method using JavaScript? I want to use a for loop like this:
var node_ids = ["123","456","789"];
var field_ids = ["abc","def","ghi"];
for (i = 0; i < node_ids.length < i++){
// MAKE DELETE REQUEST to "https://graph.facebook.com/v2.5/" + node_ids[i] + "/{{EDGE_NAME}}/?field_ids=['" + field_ids[i] + "']";
}
I saw a code like this online that I thought might be applicable, but I don't know how it works...
$.ajax({
url: '/script.cgi',
type: 'DELETE',
success: function(result) {
console.log(result)
}
});
It looks like jquery but I guess it must be ajax? Does ajax need a library to be referenced like jquery does? Is it as simple as putting this function inside my for-loop and passing the URL I'm building inside the for loop to the 'url' field in the ajax call...?
What is the best function to pass to the 'success' parameter here so I know my request was successful? Is it possible to return the response from the delete request i.e. success:true if it works?
The more explicit you can be, the better!
Do you foresee any issues with me looping through 8000 entries across two arrays (one contains the node ID / object I am editing, and one contains a field related to the edge I'm accessing which will delete aka 'remove' the assignment from the node I am accessing...?
Thanks!