Requested entity was not found when trying to send a push notification using Firebase Cloud Messaging in Firebase Cloud Functions

Sebastien picture Sebastien · May 20, 2019 · Viewed 14k times · Source

I'm trying to send a multicast notification via FCM from a Firebase Cloud function with the following code:

const message = {
    tokens: recipients,
    notification: {
        title: title,
        body: body
    },
    data: {
        projectPartnerId: projectPartnerId
    }
};
return admin.messaging().sendMulticast(message);

And none of the push notifications is getting sent. Each response contains an error with the same message: "Requested entity was not found".

I enabled the API in the Google Cloud console (which was not mentioned anywhere in the Firebase documentation but apparently that was necessary). I don't know what else I can do. And all the other questions I could find related to the HTTP API or the legacy API. I'm using the latest version of the Firebase Admin SDK.

Answer

Sebastien picture Sebastien · May 20, 2019

Figured it out. So apparently, this error happens when the FCM token I'm trying to send to is not registered anymore, as evidenced by the "messaging/registration-token-not-registered" error code. In that case I just need to remove this token from the user's token and be done with it.