Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member Exists error when using client.lists.members.create_or_update #222

Open
DataGreed opened this issue Feb 26, 2020 · 1 comment
Open

Comments

@DataGreed
Copy link

When using client.lists.members.create_or_update method I get this error if the user actually exists (the actual email is hidden for privacy concerns):

MailChimpError: {'type': 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/', 'title': 'Member Exists', 'status': 400, 'detail': '(SOME_EMAIL_HERE)@domain.com is already a list member. Use PUT to insert or update list members.', 'instance': 'd9d8f23a-87e9-4add-9fb3-204ccb0151d9'}
 ...
  File "mailchimp3/entities/listmembers.py", line 165, in create_or_update
    return self._mc_client._put(url=self._build_path(list_id, 'members', subscriber_hash), data=data)
  File "mailchimp3/mailchimpclient.py", line 30, in wrapper
    return fn(self, *args, **kwargs)
  File "mailchimp3/mailchimpclient.py", line 257, in _put
    _raise_response_error(r)
  File "mailchimp3/mailchimpclient.py", line 44, in _raise_response_error
    raise MailChimpError(error_data)

This is are the arguments aI use to call the method:

data={
    email_address: '(SOME_EMAIL_HERE)@domain.com',  
    merge_fields: {
        EMAIL: '(SOME_EMAIL_HERE)@domain.com', 
        NAME: 'Kate'
    }, 
    status: 'subscribed', 
    status_if_new: 'subscribed'
}

client.lists.members.create_or_update(
    list_id=audience_id,
    subscriber_hash=md5(user.email.lower().encode("utf-8")).hexdigest(),
    data=data)

Library version is 3.0.12 running on Python 3.6

This seems strange as I am using create_or_update method which assumes that the user can already exist and I think that create_or_update actually uses PUT method.

Am I doing something wrong here? How can this be fixed?

@stephenross
Copy link
Collaborator

@DataGreed I will need to look further into this, but for starters, we do have a helper function called check_subscriber_hash that lives in mailchimp3.helpers that you can use to convert an email address to a hash without any additional changes. We do also run that on anything that expects a subscriber hash so you can provide either the hash or the email address raw to that kwarg.

It is possible that the hash that you provided does not match the hash that Mailchimp has, so when you attempted to update the user, it was looking for a record at say XYZ, didn't find it, checked the email and saw ABC, tried to create that record, and found an existing record for ABC. You must supply the subscriber hash that MailChimp already has in the system if you are attempting to change a user's email address and this function is one of the few ways you can make that change, though the hash you provide would need to be for the old email, and the hash you get back would match their new email address. Try using the helper function or passing the email straight, and if you are still having problems, we might need more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants