Closed mtuchi closed 1 year ago
The Mailchimp Marketing API has a limit of 10 concurrent connections for your API key. The current implementation for Delete member tags will experience this limit if we have more than 10 records that needs to be deleted.
We can solve the API limit issue by using batch operation for deleting members tags in bulk and use batch webhooks to received response for enqueue batch request
Delete member tags in bulk
Trigger: Every 30 mins
Job 1 GET
Campaign Members Deleted records in Salesforce created since the last run
//Setup lastRunDatetime r
fn(state=>state)
// Get deleted campaign members from Salesforce query(...);
// map deleted members to operation chunks fn((state) => { const deletedCampaignMembers = state.references[0]["records"]; const operations = [];
for (const member of deletedCampaignMembers) {
operations.push({
method: "POST",
path: /lists/a4e7ea0abc/members/${member.Email__c}/tags
,
operation_id: ${member.Email__c}
, // Unique operation id, To make this unique we should append a number
body: JSON.stringify({
is_syncing: true,
subscriber_hash: member.Email__c,
tags: [{ name: member.Nome_da_Tag__c, status: "inactive" }],
}),
}); } // Chunk operations to 500 records const chunkedOperations = chunk(operations, 500); return { ...state, references: [], chunkedOperations, }; });
Job 2 Remove member tags from Mailchimp
POST
/batches
{"operations":[]}
each(
'operationsBatch[*]',
post('/batches', state => ({
operations: state.data,
}))
);
Confirm deleted member tags Trigger: Incoming webhook message on openfn.org
Pros
Cons
Read more about running batch operations here - https://mailchimp.com/developer/marketing/guides/run-async-requests-batch-endpoint/#make-a-batch-operations-request
Background, context, and business value
See readme
The specific request, in as few words as possible
Job 1 - GET Campaign Members Deleted records in Salesforce created since the last run Object: Campaign Members Deleted Query:
Job 2 - Remove member tags from Mailchimp
POST /lists/{list_id}/members/{subscriber_hash}/tags
API endpoint: Add or remove member tags Path parameters: list_id and subscriber_hash (string type) Body parameters:tags (object[name;status = "inactive""])
Documentation:
Expected data volumes
See diagram here