question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FR] Issue with sendMulticast of admin SDK for FCM.

See original GitHub issue

Are you in the right place?

Looks like I have run into some sort of bug with the Admin SDK. I am using Firebase Cloud Messaging to send Push Notification to iOS device. I am using the Admin SDK to send the message.

Describe your environment

  • Operating System version: macOS Catalina 10.15.5
  • Firebase SDK version: Firebase CLI (8.6.0) and Firebase Admin SDK (8.10.0)
  • Firebase Product: Firestore/FCM/Firebase Admin SDK
  • Node.js version: 14.5.0 and Node Engine 10
  • NPM version: 6.14.5

Describe the problem

I am sending Push Notification (silent). I am using sendMulticast(message) of Admin SDK. It works fine with the following Message Payload:

const message = {
                data: {
                    id: userId
                },
                tokens: deviceTokens
            }

deviceTokens is an array of tokens. But this is payload for Android and it works for Android devices.

I also need to send Silent Push Notification to iOS. So I changed my payload to:

const message = {
                data: {
                    id: userId
                },
                apns: {
                    headers: {
                       "apns-priority": "5",
                       "apns-push-type": "background"
                    },
                    payload: {
                        aps: {
                            "content-available": "1",
                            "data": {
                                "id": userId
                            }
                        }
                    }
                },
                tokens: deviceTokens
            }

Here, this fails with an error: Error: Exactly one of topic, token or condition is required at FirebaseMessagingError.FirebaseError [as constructor]

It fails when I add the apns dictionary.

I’ve been through the documentation and everything else, even through the admin.messaging.MulticastMessage source code and the interfaces for MulticastMessage and I’m not doing anything wrong (looks like it).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hiranya911commented, Aug 7, 2020

One possibility is your deviceTokens array containing some incorrect values. I was only able to reproduce the above error when my tokens array contained null, empty string, or some other invalid item.

0reactions
harshittrehancommented, Aug 7, 2020

One additional thing, and I just tested it right now, if I send the empty string without using the ‘apns’ key, then I don’t get the error.

const message = { data: { id: userId }, tokens: deviceTokens }

^ This doesn’t give an error if deviceTokens contains “” empty string. But with ‘apns’ key added, it does fail. That seems kinda funky and something you might want to check out @hiranya911

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase admin SDK FCM error Exactly one of topic, token or ...
When we send empty fcm token, Firebase gives us below error ... but to send to an array of tokens, you need to...
Read more >
Messaging class | Firebase Admin SDK - Google
sendMulticast (message, dryRun), Sends the given multicast message to all the FCM registration tokens specified in it.This method uses the sendAll() API ......
Read more >
Firebase Admin SDK for PHP - Read the Docs
Firebase Admin SDK for PHP. 2.3.3 Send messages to topics. Based on the publish/subscribe model, FCM topic messaging allows you to send a ......
Read more >
firebase - Bountysource
i checked Firebase Cloud Messaging Api in Google Cloud Platform console and see increasing 404 answer for Api Method google.firebase.fcm.v1.FcmService.
Read more >
Firebase Cloud Messaging (FCM) - Notifee
' }, }); } // Send messages to our users sendMessage();. The admin SDK will send a data payload to all devices with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found