mailerlite / mailerlite-go Goto Github PK
View Code? Open in Web Editor NEWGo SDK for MailerLite
License: MIT License
Go SDK for MailerLite
License: MIT License
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: "[email protected]",
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.
Automations:
Batching:
Timezones:
Campaign languages:
I'd like to be able to unit test my code that I use for Mailerlite access. Ideally I would just take an interface from the package and supply a custom type that satisfies the interface and returns the responses I need for testing. However the issue is that there doesn't exist such an interface and I can't create one myself because there are unexported types returned. Specifically I can mention SubscriberService
where operations often return a *rootSubscriber
which I can neither add to my own interface nor would be able to return as part of a custom struct.
Please consider a way to help unit test external usages of this package
Hello, I am trying to add a new subscriber using go and gin-gonic, but I keep getting an error
"error": "POST https://connect.mailerlite.com/api/subscribers: 422 The groups field must be an array. map[groups:[The groups field must be an array.]]",
Here is my code
var MAILERLITE_API = os.Getenv("MAILERLITE_API")
func SaveNewsletter() gin.HandlerFunc {
return func(c *gin.Context) {
client := mailerlite.NewClient(MAILERLITE_API)
ctx := context.TODO()
subscriber := &mailerlite.Subscriber{
Email: "[email protected]",
Fields: map[string]interface{}{
"city": "Vilnius",
},
}
newSubscriber, _, err := client.Subscriber.Create(ctx, subscriber)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()})
return
}
log.Println(err, newSubscriber)
c.JSON(http.StatusOK, gin.H{
"success": true,
"subscriber": newSubscriber.Data,
})
}
}
Calling the client.Campaign.List
method results in the following error:
json: cannot unmarshal array into Go struct field Campaign.data.settings of type mailerlite.CampaignSettings
The API version that the client specifies (2022-12-01) causes the server to return an array for the 'settings' field of a campaign, while the client expects an object. (It looks like the server started returning an object instead of an array at version 2023-01-11).
I suspect this is an issue with the web service (not this Go client) but I am raising this here with the hope that it gets escalated to the right team.
Take a look at this function.
According to the API docs, the timezone_id
"Must be a valid timezone id, defaults to the account's timezone id". This means it will use the timezone id if it's passed, otherwise, it will use the account's timezone.
On the dashboard, update your account time zone to any that is ahead of UTC; e.g. "Asia/Tokyo".
Now, if you call the campaign scheduling function as I did above, and pass 426 (UTC) to TimezoneID
(assuming you execute the program on a machine with UTC time zone), the call with fail with:
POST https://connect.mailerlite.com/api/campaigns/${CAMPAIGN_ID}/schedule: 422 Please select time in the future map[schedule.hours:[Please select time in the future]].
However, if you change the timezone on the dashboard to UTC, the API succeeds.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
This repository currently has no open or pending branches.
.github/workflows/test.yaml
actions/checkout v4
actions/setup-go v5
go.mod
go 1.18
github.com/google/go-querystring v1.1.0
github.com/stretchr/testify v1.9.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.