mailerlite / mailerlite-go

Go SDK for MailerLite
MIT License
3 stars 3 forks source link

Subscriber creation function is broken #10

Closed wilburx9 closed 1 year ago

wilburx9 commented 1 year ago

The implementation of the subscriber creation function doesn't comply with the REST API docs.

In the linked doc, only the email is required and the groups is an array of group ids. However, this call:

subscriber := &mailerlite.Subscriber{
    Email:  "example@example.com",
    Groups: []mailerlite.Group{{ID: "12345"}},
}

client.Subscriber.Create(ctx, subscriber)

Fails with:

POST https://connect.mailerlite.com/api/subscribers: 422 Must be a valid object (and 1 more error) map[fields:[Must be a valid object] groups.0:[The groups.0 must be a number.]]

This is because the whole Subscriber struct is being marshalled and sent along with the request.

For now, I have resorted to calling the endpoint directly.