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

Tags not being set with list.UpdateUser #34

Open
montanaflynn opened this issue Aug 6, 2019 · 9 comments
Open

Tags not being set with list.UpdateUser #34

montanaflynn opened this issue Aug 6, 2019 · 9 comments

Comments

@montanaflynn
Copy link

I'm trying to update a users tags, I don't get an error but the tags are not being updated:

	req := &gochimp3.MemberRequest{
		EmailAddress: "[email protected]",
		Tags:         []string{"verified"},
	}

	m, err := list.UpdateMember("a36670ebcefcd9800c286cfbb101888f", req)
	if err != nil {
		fmt.Printf("Failed to update members %q\n", listID)
		os.Exit(1)
	}

	fmt.Printf("%+v\n", m)

Related: #31 cc @zeekay

@royalgiant
Copy link

I'm getting the same issue here.

@royalgiant
Copy link

Looks like the mailchimp api doesn't support tags for updates :( https://mailchimp.com/developer/reference/lists/list-members/#create-post_lists_list_id_members

@montanaflynn
Copy link
Author

@royalgiant I see tags at the bottom of the Request Body Parameters section.

@royalgiant
Copy link

@royalgiant I see tags at the bottom of the Request Body Parameters section.

Check under the "EDIT" instead of the "CREATE" section

@davidtai
Copy link
Contributor

davidtai commented Dec 7, 2019

This is very odd, tags is clearly on the Member request object with the correct parameter name.

type MemberRequest struct {

@royalgiant
Copy link

This is very odd, tags is clearly on the Member request object with the correct parameter name.

type MemberRequest struct {

@davidtai problem is I don't think Mailchimp accepts tags for edit members

@montanaflynn
Copy link
Author

@royalgiant thanks, I was looking at CREATE and not EDIT.

I found this which could possibly be used:

https://mailchimp.com/developer/reference/lists/list-members/list-member-tags/

@royalgiant
Copy link

@montanaflynn @davidtai You're going to kiss me for this.

// struct for Mailchimp's member tags
type MailChimpTags struct {
	Name   string `json:"name"`
	Status  string `json:"status"` // 2 options: 'active' and 'inactive' to add and remove tags respectively
}

var member_tags []MailChimpTags 

member_tags = append(member_tags, MailChimpTags{Name: fill_in_name, Status: "active"})

endpoint := fmt.Sprintf("/lists/%s/members/%s/tags", fill_in_list, fill_in_email_address)

// errorz variable because i'm a gangster. :)
if errorz := client.Request("POST", endpoint, nil, map[string]interface{}{"tags": member_tags}, nil); errorz != nil {
			log.Println("the err %v", errorz)
		}

That's what worked for me. Let me know if it helps.

@montanaflynn
Copy link
Author

@royalgiant 😚

client := gochimp3.New(apiKey)

type MailChimpTags struct {
    Name   string `json:"name"`
    Status string `json:"status"` // 2 options: 'active' and 'inactive' to add and remove tags respectively
}

var memberTags []MailChimpTags

for _, tag := range tags {
    memberTags = append(memberTags, MailChimpTags{Name: tag, Status: "active"})
}

loweredEmail := strings.ToLower(email)
md5Sum := fmt.Sprintf("%x", md5.Sum([]byte(loweredEmail)))

endpoint := fmt.Sprintf("/lists/%s/members/%s/tags", listID, md5Sum)

err := client.Request("POST", endpoint, nil, map[string]interface{}{"tags": memberTags}, nil)
if err != nil {
    return err
}

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

3 participants