3

I'm using Firebase Cloud Functions to send notifications to users when certain events in Firestore are triggered. The example code below was working some time ago, but now I'm getting an error when I try to run this code

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'

admin.initializeApp();

export const onGenderChange = functions.firestore.document('users/fOZFJvfDwhXCFnXjyWtlEYcf2kM2').onUpdate((change, context) => {
    const message = {
        data: {
            time: 'a',
            score: 'b',
            click_action: 'FLUTTER_NOTIFICATION_CLICK'
        },
        token: 'e1P2KLrNNss:APA91bH4b__7VA-QpUMSPCKMcG91TITF8B23CMYWkyfAcnleCbJfA3QPyhLNJABDm8KHlNmNBGAN48UiNQ67yoCrRLXqXqfH0OhJR5RwNHstFq1gEmXxGR-aUrxf5PWyrQrjk7D3m__n'
    };
    return admin.messaging().send(message);
});

Error messgae:

Error: Requested entity was not found.
    at FirebaseMessagingError.Error (native)
    at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
    at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
    at Function.FirebaseMessagingError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:271:16)
    at FirebaseMessagingRequestHandler.handleHttpError (/user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:125:50)
    at /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:113:23
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Function is triggered, token is valid, because I can send notifications to that user manually from the Firebase console. What could cause this error? Wrong configuration of Cloud Functions project, wrong versions or something else?

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Vadims Savjolovs
  • 2,218
  • 22
  • 47

0 Answers0