mailchimp-api icon indicating copy to clipboard operation
mailchimp-api copied to clipboard

Struggling to remove a tag from a user

Open Gigamick opened this issue 5 years ago • 5 comments

I can add tags successfully but when I try to delete a tag from a user I get an error.

Here's my code:

$m = new MailChimp($apiKey);
        $m->delete("lists/".$listId."/members/".$memberId."/tags", [
            'tags' => [
                [
                    'name' => $tag,
                    'status' => 'active',
                ],
            ]
        ]);

The error I'm getting is

ErrorException: Undefined offset: 1 in file /Users/mick/repos/sbx/vendor/drewm/mailchimp-api/src/MailChimp.php on line 340

Thanks 🤘

Gigamick avatar Jul 22 '20 22:07 Gigamick

@drewm sorry to tag you directly. Do you have any insight into what's wrong here?

Gigamick avatar Aug 27 '20 21:08 Gigamick

From my understandings of what I find on https://mailchimp.com/developer/api/marketing/list-member-tags/ the only difference between adding or deleting would be setting the status to active or inactive.

But when I try to add a tag with this code:

$result = $MailChimp->post("lists/${list_id}/members/${subscriber_hash}/tags",[ 'name' => 'TestTag', 'status' => 'active', ]);

I don't get an error but the tag doesn't get added. Could you tell me how you did it to add a tag? Maybe just changing 'active' to 'inactive' would solve your problem. Thanks in advance!

sugus67 avatar Sep 29 '20 21:09 sugus67

hey, @GigaMick, @sugus67 you can try this.

$result = $MailChimp->post("lists/$list_id/members/$subscriber_hash/tags", [
    'tags' => array(
         [
            'name' => 'tagname',
            'status' => 'inactive'
         ],
        [
           'name' => 'othertag',
            'status' => 'active'
        ]
     )
]);

noproblematall avatar Oct 14 '20 01:10 noproblematall

You can add a tag like this:

$result = $MailChimp->post("lists/$list_id/members/$subscriber_hash/tags", [ 'tags' => array( 'your tag') ]);

But I am struggling to remove tags too.

mcrnbrck avatar Nov 20 '20 02:11 mcrnbrck

For future reference.

As listed in the mailchimp api docs a status property has to be passed along with the tag name.

$MailChimp->post("lists/$list_id/members/$subscriber_hash/tags", [
  'tags' => [
        [
            'name' => 'your-tag-name',
            'status' => 'inactive',              // Active will add the tag, inactive will remove the tag
        ]
    ]
]);

Trekels avatar Dec 08 '21 19:12 Trekels