rainlab / mailchimp-plugin

Provides MailChimp integration services
MIT License
11 stars 16 forks source link

Add tags to new subscriber email #32

Closed mskraban closed 4 years ago

mskraban commented 4 years ago

I'm trying to add tags, but no success. Don't know if this is the correct way of adding tags, but I'm getting error of "Undefined offset: 1 on drewm/mailchimp-api/src/MailChimp.php Do tags work in this version or I'm doing it wrong?

$subscriber_hash = $MailChimp->subscriberHash(post('email')); 
//$result = $MailChimp->put("lists/".$this->property('list')."/members/". $subscriber_hash, $subscriptionData);
        $result = $MailChimp->put("lists/".$this->property('list')."/members/$subscriber_hash/tags", [
            'tags' => [
                [
                    'name' => 'team',
                    'status' => 'inactive',
                ],
            ]
        ]);
LukeTowers commented 4 years ago

It's possible they aren't. Feel free to dig into the library we're using and if necessary make a PR to a better one.

mskraban commented 4 years ago

I have found the solution. Member list accepts PUT for adding and updating existing members info, Tags accept only POST method. And both methods have to be separated.

$subscriber_hash = $MailChimp->subscriberHash(post('email')); 
$result = $MailChimp->put("lists/".$this->property('list')."/members/". $subscriber_hash, $subscriptionData);
        $result = $MailChimp->post("lists/".$this->property('list')."/members/$subscriber_hash/tags", [
            'tags' => [
                [
                    'name' => 'team',
                    'status' => 'inactive',
                ],
            ]
        ]);