1

I am trying to implement sending more than a 1000 notifications at a time. My mobile app has to notify workers in a city about new job offerings and I have to notify them.

However, in the docs it says that the limit is a 1000 keys in the array so that I can do:

admin.messaging().sendToDevice(...arrayOfThousandKeys, payload);

How can I send more than a 1000? Do I split it in 2 or more arrays? Everything is appreciated!

Walter Monecke
  • 2,386
  • 1
  • 19
  • 52

1 Answers1

2

Yes, just call the API as many times as needed to send all the messages.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • I was doing so by calling `sendToDevice` in a for loop, each time with a single but different fcmToken and apparently got rate limited. It has to be an array right? – Walter Monecke Dec 09 '18 at 20:47
  • I don't know why you wouldn't want to max out the array every call. – Doug Stevenson Dec 09 '18 at 20:53
  • Id have to handle the partition into several arrays etc – Walter Monecke Dec 09 '18 at 20:57
  • Yes, but each array can be 1000 tokens. So if you're sending to 3000 tokens, that'd be 3 API calls. Btw: even if you'd do 3000 calls, you won't get rate limited. – Frank van Puffelen Dec 09 '18 at 23:52
  • 1
    I did around 300 `.sendToDevice()` calls. Each call with a single token and after the 100th call or so I got the following message `fcm.googleapis.com network timeout. Please try again.` – Walter Monecke Dec 10 '18 at 15:45