Getting an "to" must be a string, "to" must be an array error for sendPushNotificationsAsync

Please provide the following:

  1. expo-server-sdk: “^3.4.0”
  2. Platforms(Android/iOS/web/all): iOS

I’m currently using expo-server-sdk to send a multiple push notifications, but getting the following error:

{ Error: “value” must be an object, “value” at position 0 fails because [child “to” fails because [“to” must be a string, “to” must be an array]].

Valid push tokens are passed to expo.chunkPushNotifications, but when chunk is passed to expo.sendPushNotificationsAsync(chunk), I get the error message mentioned above:

(async () => {
  for (let chunk of chunks) {
    try {
      let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
      tickets.push(...ticketChunk);
    } catch (error) {
      console.error(error);
    }
  }
})();

The chunk is in the following form:

[ { to:
     { notificationToken: 'ExponentPushToken[some_push_token]' },
    sound: 'default',
    body: 'This is a test notification',
    data: { withSome: 'data' } },
]

which means the chunks is in the from of an array of an array of objects:

[ [ { to: [Object],
      sound: 'default',
      body: 'This is a test notification',
      data: [Object] },
]]

Hey @igibliss00,

This is because you have an object as the value for the to property when it should be a string.

It should be to: 'ExponentPushToken[some_push_token]'

Cheers,
Adam

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.