VingtCinq / python-mailchimp

Python client for v3 of MailChimp API
MIT License
463 stars 131 forks source link

can I add a tag when using lists.members.create_or_update? #203

Closed andrewdj closed 5 years ago

andrewdj commented 5 years ago

I am looking at tags and groups to mark signup state, and wondering if I can add either as part of the create_or_update() call?

e.g.:

self.mailchimp.lists.members.create_or_update( self.mailing_list_id, m.hexdigest(), { "status": "subscribed", "status_if_new": "pending", "email_address": email_address, "tags": ["Incomplete"] })

stephenross commented 5 years ago

According to https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#edit-put_lists_list_id_members_subscriber_hash, no. If you want to add tags, you will need to use create_or_update(), and then use the lists.members.tags.update() function on that user. When you use the lists.members.create_or_update() call, the wrapper will stash the subscriber hash for that call at lists.members.subscriber_hash, assuming no other calls in the lists.members section specifically are made after. You can use this to shortcut some of the information needed to add tags to the member that you want. As a note, the format for adding tags in that manner would look like the following:

self.mailchimp.lists.members.tags.update(
  self.mailing_list_id,
  m.hexdigest(),
  {
    'tags': [
      {'name': 'Incomplete', 'status': 'active'},
    ],
  }
)
octavioamu commented 5 years ago

I think is update not create, right?

self.mailchimp.lists.members.tags.update(
  self.mailing_list_id,
  m.hexdigest(),
  {
    'tags': [
      {'name': 'Incomplete', 'status': 'active'},
    ],
  }
)

Also Im having an issue on production, I need to enable something on mailchimp side? Seems I'm able to do it on my dev env but getting 'ListMembers' object has no attribute 'tags' on production.

stephenross commented 5 years ago

@octavioamu You are correct, it should be update. I have edited my comment. For your issue with production, you likely need to update the version of the wrapper. Support for the member tags endpoint was added in version 3.0.6, so you will need at least that version to function with those endpoints.

octavioamu commented 5 years ago

@octavioamu You are correct, it should be update. I have edited my comment. For your issue with production, you likely need to update the version of the wrapper. Support for the member tags endpoint was added in version 3.0.6, so you will need at least that version to function with those endpoints.

Thanks @stephenross for the fast response, yes I just figured out was a version problem, production was on 3.0.4 bumped to 3.0.7 and now is working fine.

DataGreed commented 4 years ago

Uhmm, I cannot make any sense of this SDK in case of tags.

self.mailchimp.lists.members.tags.update(
  self.mailing_list_id,
  m.hexdigest(),
  {
    'tags': [
      {'name': 'Incomplete', 'status': 'active'},
    ],
  }
)

First of all, why tags are mentioned two times? there is an interface object and (members.tags property) and a key in data dictionary.

Second, why tags is a dictionary and not an array? Whay kind of values are expected there? In mailchimp dashboard tags are just labels with no value expected, what should I pass there?.. I am totally confused

DataGreed commented 4 years ago

Wait, do i have to support active value to all tags? o.O Why is it like that?

octavioamu commented 4 years ago

@DataGreed please check the api docs, I understand your complains but are not related to this library are actually related to how the mailchimp API was designed https://mailchimp.com/developer/guides/how-to-use-tags/