Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a member's group interests using MailChimp API V3

I am running the following code (I've hidden ID's) to add/update a subscriber's interest groups in a MailChimp list:

$mailchimp->patch('lists/1234567/members/' . md5('[email protected]'), [
    'status' => 'subscribed',
    'merge_fields' => array(
        'FNAME' => 'Ben',
        'LNAME' => 'Sinclair',
    ),
    'interests' => array(
        'abcd1234' => true,
        'defg6789' => true,
    ),
]);

The interests key is what I'm having issues with.

I presumed whatever you put in this key will overwrite what currently exists.

It doesn't seem to be the case. It only adds new interests but does not remove any if the ID's are not in the array. I am not getting any errors.

Does anyone know how to overwrite interest groups? Or if that's not possible, is there a way to remove interest groups?

like image 826
Ben Sinclair Avatar asked May 16 '16 06:05

Ben Sinclair


People also ask

How do I use Mailchimp API in Postman?

First of all, we need to download Postman - a program for testing requests. We will create our request and send it to the platform in it. Thus, we can check if our request is correct and if all the data goes to the platform. Next, we will create a request URL and body and will test their work in Postman.

How do I add a subscriber to my Mailchimp API?

Create Mailchimp API keysGo to mailchimp select account, you will find extras dropdown. Select API keys and in the bottom left you will find a button Create A Key . Click on it and your api key is created. You have to copy the API Key under the API Key header.


1 Answers

For completion I wanted to add this answer so people stumbling upon this post can find a quick solution.

$mailchimp->patch('lists/1234567/members/' . md5('[email protected]'), [
    'status' => 'subscribed',
    'merge_fields' => array(
        'FNAME' => 'Ben',
        'LNAME' => 'Sinclair',
    ),
    'interests' => array(
        'abcd1234' => true, // Attached
        'defg6789' => false, // Detached
    )
]);

In this example the interest 'abcd1234' will be attached and the interest 'defg6789' will be detached.

Other interests that are not listed will remain on their original value.

like image 101
Sam Avatar answered Oct 31 '22 22:10

Sam