nmit026
nmit026

Reputation: 3364

Mailchimp - how can I tell if a user has unsubscribed themselves?

So they've clicked the unsubscribe link in a newsletter. In their profile it says, for example:

This person unsubscribed on Mar 24, 2017 2:40 pm

After receiving "Newsletter Test#6"

Great, but how can I tell programmatically, via the API, if someone has unsubscribed themselves? Is it even possible? The reason I'm asking is because you can't delete someone who has unsubscribed themselves. If you try, their data will be scrubbed but the email address will stay in your list. Furthermore, if you try to subscribe someone who has unsubscribed by clicking on an unsubscribe link, you'll get "[email protected] is in a compliance state due to unsubscribe, bounce, or compliance review and cannot be subscribed." So in this situation we should check if they've unsubscribed themselves, and if so we can set their status to pending which will send the confirmation opt-in email. Otherwise, we can subscribe them via API without setting their status to pending and sending them an email and requiring them to click the link in the email.

Upvotes: 3

Views: 3242

Answers (3)

You Old Fool
You Old Fool

Reputation: 22941

To expand on the answer from @nmit026, do a get-member-info api request and check for:

unsubscribe_reason == 'N/A (Unsubscribed by admin)'

In my opinion, this feels a bit hacky as the logic relies on comparison to a fairly specific string, but nonetheless, it is probably only correct approach at the moment.

Upvotes: 0

You Old Fool
You Old Fool

Reputation: 22941

As you've noted, if you try to delete someone in a compliance state, the API will reject your request but unfortunately doesn't return any useful response indicating as such. On the other hand, if you try to subscribe someone in a compliance state you should get a response in json form with status of 400 and a corresponding message. In my case it looks something like this:

{
    "type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
    "title":"Member In Compliance State",
    "status":400,
    "detail":"[email protected] is in a compliance state due to unsubscribe, bounce, or compliance review and cannot be subscribed.",
    "instance":"1234567890abcdefg"
}

If you simply parse that response you can check for the value of status which is probably more reliable and forward compatible than the textual descriptors - and if applicable you can set member state to pending from there.

Upvotes: 2

nmit026
nmit026

Reputation: 3364

From Mailchimp support:

When a user is unsubscribed you'll see the parameter unsubscribe_reason and if it's an admin unsubscribe or an unsubscribe done via the API it will say "N/A (Unsubscribed by an admin)". However if it is done by the user it will often say "Unspecified" if they did not leave a reason or it may display a reason the user noted for unsubscribing. You can read more about the unsubscribe_reason parameter at the link below.

http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/

Upvotes: 2

Related Questions