retailcrm / api-client-go

Go client for retailCRM API
http://www.retailcrm.ru
MIT License
3 stars 21 forks source link

CustomerCreate returns error when using tags #46

Closed tirprox closed 3 years ago

tirprox commented 3 years ago

When attempting to create a customer through client, I'm getting an error:

apiErrs: key = "tags" value = "The following tags are invalid: Array\n"

For example:

phone := v5.Phone{Number: lead.Phone}

tag := v5.Tag{
    Name: "opt-lead",
}
tags := []v5.Tag{}
tags = append(tags, tag)
customer := v5.Customer{
    FirstName: lead.Name,
    Email:     lead.Email,
    Phones:    []v5.Phone{phone},
    Tags:      tags,
    Site:      "opt.dreamwhite.ru",
}

resp, status, err := tools.RetailClient.CustomerCreate(customer, "opt")

This probably means that since updating Customer with Tags in #40 RetailCRM backend still expects just an array of strings instead of an array of objects with name and color

Neur0toxine commented 3 years ago

Hello! First of all, thanks for your contribution. Yes, RetailCRM API expects tags in form of an array of strings while creating a customer, but for GET methods it will return an array of objects with fields specified in the Tag structure.

To keep compatibility with this behavior we will implement json.Marshaler for the Tag structure in the next update. It will marshal only the name field as a string, which will fix the problem you reported. You'll still need to provide a slice where each element is a whole Tag structure, but only name field will be used there.