Just tested the MailerLite SDK and there appears to be some inconsistencies with the API & SDK about the groups field on the user object.
- I get a subscriber via
mailerlite.subscribers.find(email)
- then add the subscriber to a group via
mailerlite.groups.assignSubscriber(subscriberId, groupId) (groupId is REQUIRED to be provided as a string)
The next time I get the user and try to update it via createOrUpdate, error throws:
- I get a subscriber via
res = mailerlite.subscribers.find(email)
- Change something in the fields:
res.data.data.fields.name = "fluff"
- send the data via
mailerlite.subscribers.createOrUpdate(res.data.data) and it throws:
> MailerLite/Index: Internal Error 422 {
> message: 'The groups.0 field must be a number. (and 1 more error)',
> errors: {
> 'groups.0': [
> 'The groups.0 field must be a number.',
> 'The selected groups.0 is not numeric.'
> ]
> }
> }
Apparently, the createOrUpdate API expects the groups to be an array of numbers? But the MailerLite Dashboard works as expected. And the mailerlite.groups.assignSubscriber expects the groupId to be provided as a string, and thus also stores it as a string into the array of the user object in the database?
Workaround
Since the createOrUpdate function appears to work as a merge with all the information in the database. The workaround is to simply remove the groups field from any updates or just provide a object with only the fields one wants to update:
const data = {
email: res.email,
fields: {
name: 'MY NAME IS TEST',
},
}
const res2 = await createOrUpdateSubscriber(data)
console.log(res2)
Just tested the MailerLite SDK and there appears to be some inconsistencies with the API & SDK about the
groupsfield on the user object.mailerlite.subscribers.find(email)mailerlite.groups.assignSubscriber(subscriberId, groupId)(groupIdis REQUIRED to be provided as a string)The next time I get the user and try to update it via
createOrUpdate, error throws:res = mailerlite.subscribers.find(email)res.data.data.fields.name = "fluff"mailerlite.subscribers.createOrUpdate(res.data.data)and it throws:Apparently, the
createOrUpdateAPI expects the groups to be an array of numbers? But the MailerLite Dashboard works as expected. And themailerlite.groups.assignSubscriberexpects thegroupIdto be provided as a string, and thus also stores it as a string into the array of the user object in the database?Workaround
Since the
createOrUpdatefunction appears to work as amergewith all the information in the database. The workaround is to simply remove thegroupsfield from any updates or just provide a object with only the fields one wants to update: