Skip to content

createOrUpdateSubscriber throws error when group was assigned via sdk #71

Description

@chrisspiegl

Just tested the MailerLite SDK and there appears to be some inconsistencies with the API & SDK about the groups field on the user object.

  1. I get a subscriber via mailerlite.subscribers.find(email)
  2. 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:

  1. I get a subscriber via res = mailerlite.subscribers.find(email)
  2. Change something in the fields: res.data.data.fields.name = "fluff"
  3. 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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions