function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robin BarnwellRobin Barnwell 

Updating Mailchimp Interests from Salesforce

I am loading Mailchimp from Salesforce using the sync tool they provide.  In Mailchimp I have a single list with multiple Interests set-up for each of the various Newsletters we send.

The initital creation of the Mailchimp Subscriber is fine.  They are added to the List and the relevant Interests.  Users could update their Interest preferences in Mailchimp, but I need to send the update from Saleforce instead. But the mailchimp sync doesn't support updates just inserts of Interests.  The Mailchimp support team confirmed this and suggested if I wanted to send updates use the API.

The best solution I have found is to build an Apex Callout that connects to the Mailchimp REST API direct and updates the specifc subscriber via a REST PATCH request.  A bit like this:

PATCH us16.api.mailchimp.com/3.0/Lists/ace5lkhkjh0a0/members/7949a7471b989ihoh5a9d1cd019521c 
{
        "id": "7949a74745345kje53a5a9d1ihjhh19521c",    
        "email_address": "robin@barnwell.com",
        "interests": {  "0dbefbe5e1": true,        
            "4b753026e3": false,        
            "f1a1024d50": true,        
            "27d6bdd94c": false,        
            "bcba00e738": true,       
            "ea22f7c19b": false,        
            "ff7a174d51": true }}

I would invoke this class through Process Builder when the contact record fields change.

Question is, has anyone already done this and please could you share the code?  

Regards Robin