Delete multiple MCFX Contacts or Deals via JavaScript

Posted by: Ariel Vertudes Date Posted: October 25, 2024
Back to Case Studies

Issue

We don’t have API endpoints to delete Contacts or Deals in bulk, and doing so on Workato or Zapier consumes a lot of tasks.

Solution

Run a JavaScript script on your browser’s console that will delete multiple MCFX Contacts or Deals.

Achievement

We can now delete multiple MCFX Contacts or Deals without using Workato or Zapier resources.

Snippet/Screenshot/Link

// DELETE MCFX Contacts
var siteId = xxxx;
var apiKey = xxxx;
var query = '&createdBy=integrations';
var limit = 200;
var total = 1000;

for(var i = 0; i < (total/limit); i++) {
    var skip = i*limit;
    (async () => {
        const rawResponse = await fetch(`https://api.webfx.com/identity/contacts?$limit=${limit}&$skip=${skip}&siteId=${siteId}&$select[]=contactId${query}`, {
            method: 'GET',
            headers: { 'x-api-key': apiKey }
        });
        const content = await rawResponse.json();
        for(var x = 0; x < content.data.length; x++) {
            deleteMCFXContact(content.data[x].contactId);
            await new Promise(r => setTimeout(r, 500));
        }
    })();
}

function deleteMCFXContact(id) {
    (async () => {
        const rawResponse = await fetch('https://api.webfx.com/identity/contacts/'+id, {
            method: 'DELETE',
            headers: { 'x-api-key': apiKey }
        });
    })();
}
// END

// DELETE MCFX Deals
var siteId = xxxx;
var apiKey = xxxx;
var query = '&createdBy=import';
var limit = 200;
var total = 1000;

for(var i = 0; i < (total/limit); i++) {
    var skip = i*limit;
    (async () => {
        const rawResponse = await fetch(`https://api.webfx.com/revops/deals?$limit=${limit}&$skip=${skip}&siteId=${siteId}&$select[]=dealId&$select[]=createdBy${query}`, {
            method: 'GET',
            headers: { 'x-api-key': apiKey }
        });
        const content = await rawResponse.json();
        for(var x = 0; x < content.data.length; x++) {
            deleteMCFXDeal(content.data[x].dealId);
            await new Promise(r => setTimeout(r, 500));
        }
    })();
}

function deleteMCFXDeal(id) {
    (async () => {
        const rawResponse = await fetch('https://api.webfx.com/revops/deals/'+id, {
            method: 'DELETE',
            headers: { 'x-api-key': apiKey }
        });
    })();
}
// END