mailchimp-api
mailchimp-api copied to clipboard
Struggling to remove a tag from a user
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 🤘
@drewm sorry to tag you directly. Do you have any insight into what's wrong here?
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!
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'
]
)
]);
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.
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
]
]
]);