banana-j / bananaj

Java API wrapper for MailChimp API 3.0
MIT License
38 stars 33 forks source link

Can't get addorupdatemember to work with tags #50

Closed joranb closed 3 years ago

joranb commented 4 years ago

Hi,

I am trying to add or update members to a list. Is there a problem with tags? Because when sending tags to the API they appear like this in the JSON request:

"tags": [ { "name": "This is a tag" } ]

This gives a 400 Bad request in return.

This is when I use the Member.Builder() and add a List to tags like this:

final Member member = new Member.Builder() .emailAddress(email) .list(list) .tags(tags) .build();

And adding the member with calling addOrUpdateMember on the list. If I remove tags it works and the user gets created. With tags I get 400 Bad request from the API when performing the PUT.

Is there a bug here or do I create tags the wrong way?

According to the API docs https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/ it looks like you should pass a status as well (active or inactive), maybe the MemberTag class should be expanded? Didn't find any documentation on handling tags in the readme so I might be missing something.

Edit: Tried a little bit after searching through some php examples on stackoverflow. This is what this wrapper generates when sending MemberTag:

"tags": [ { "name": "This is a tag" } ]

The API expects:

"tags": [ "This is a tag" ]

Could get it to work that way in Postman.

gscriver commented 4 years ago

I recommend using Member. applyTag(String tagName, TagStatus status) for the interim while we sort out the issues with tags. e.g. member.applyTag("myTag",TagStatus.ACTIVE);

gscriver commented 4 years ago

According to the current Mailchimp API documentation; tags are not supported for Members PUT and PATCH operations. Tags are supported for POST operations and the tags field has a type of array, not object as is currently implemented.

We need to modify the Members JSON generation to reflect the http verb and document how tags are applied by the various create, addOrUpdate, and update methods.

joranb commented 4 years ago

Thanks for the help, using member.applyTags suffices for now. But yeah, would be nice to get that fixed by using the builder, cleaner code.

gscriver commented 4 years ago

Note that after further testing we found that this error only occurs when the addOrUpdateMember results in the creation of a new member. It does not occur for existing members or when the member has been previously archived. Tags are only applied when an underlying create operation is performed when an update operation if performed tags are ignored.