Get campaign members & add or update members and tags
Closed this issue · 0 comments
Background, context, and business value
The specific request, in as few words as possible
Every 30 minutes:
Job 1- Get Campaign Members
Get Campaign members in Salesforce created since the last job run OR the Campaign Member’s Contact updated since the last job run.
Adaptor: Salesforce
Object: Campaign Members,
Primary key (field): email,
Query:
SELECT Id, name, firstname, lastname, email, CreatedDate, Contact.AccountId, Contact.LastModifiedDate, Contact.CreatedDate, Campaign.Name, campaign.Nome_da_Tag__c FROM CampaignMember WHERE Campaign.RecordType.Name = 'Grupos, RTs ou Áreas Temáticas' and Campaign.IsActive = true and ( (Contact.LastModifiedDate > {LastSyncTime} or CreatedDate > {LastSyncTime})
Documentation:
- Salesforce API documentation: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
- Composite requests: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_composite.htm
Job 2 - Add or update members and tags
POST /lists/{list_id}
Adaptor: MailChimp
API endpoint: Batch subscribe or unsubscribe list members
Path parameters: list_id = “43fead6cd7”
Body parameters: members see mapping Specs (An array of objects, each representing an email address and the subscription status for a specific list. Up to 500 members may be added or updated with each API call.)
The job will has a loop to divide the records in two batches:
- Add member on contactsToUpdate batch;
- without "status" field in “member[ ]”;
- Add member on contactsToCreate batch;
- with "status" field setted to “subscribed” in “member[ ]”
Documentation:
- Mailchimp API documentation: https://mailchimp.com/developer/marketing/api/lists/batch-subscribe-or-unsubscribe/
- Data flow diagram: https://lucid.app/lucidchart/aa09d20c-31a7-41e3-ae0c-c1c3b5e7d5c9/edit?invitationId=inv_87b8edec-d927-4d4d-a1b3-cbffe085c068&page=0_0#
Expected data volumes
It is expected that each Campaign in Salesforce will return a maximum of 1000 records (Campaign Members). In rare exceptions, this number can reach 15,000 records.
In Salesforce, when a SOQL query is executed, up to 2,000 records can be returned at a time in a synchronous request.
Mailchimp API limits: https://mailchimp.com/developer/marketing/docs/fundamentals/#api-limits
For the batch subscribe or unsubscribe list members in Mailchimp, up to 500 members may be added or updated with each API call.
state.json
- Mailchimp’s bearer token (PRODUCTION) - Credential in VeraForce
- Salesforce’s Credential (SANDBOX) - Credential in Veraforce