hanzoai / gochimp3

🐒 Golang client for MailChimp API 3.0.

Home Page:https://github.com/zeekay/gochimp3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tags not being set with list.UpdateUser

montanaflynn opened this issue · comments

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: "montana@mathpix.com",
		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

I'm getting the same issue here.

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

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

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

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

type MemberRequest struct {

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

@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/

@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.

@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
}