mailchimpmailchimp-api-v3.0

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 "john@example.com 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.


Solution

  • 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":"johndoe@example.com 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.