Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase FCM content_available via Firebase Cloud Functions throws error

I've been trying to send push notification via Cloud Functions. This is the guide on how to do it from Firebase: https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js

This is the payload I have

const payload = {
      "notification": {
        title: 'Title!',
        body: 'Body!',
        sound: 'default'
      },
      "data":{"score":"3x1"},
      "content_available": true,
    };

Now, this throwing an error, and when I check the log, here's the error:

Error: Messaging payload contains an invalid "content_available" property. Valid properties are "data" and "notification".
    at FirebaseMessagingError.Error (native)
    at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:25:28)
    at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:130:23)
    at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:465:23
    at Array.forEach (native)
    at Messaging.validateMessagingPayload (/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:462:21)
    at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:204:37
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)

If I removing the content_available: true, it works fine, so I know the code works.

I also tried to send this manually with CURL/POST request WITH content_available: true, and it also works.

Thanks!

like image 464
ordinaryman09 Avatar asked Dec 04 '25 14:12

ordinaryman09


1 Answers

contentAvailable is passed in the options parameter of sendToDevice(regToken, payload, options). Example code is in this documentation. The documentation for MessagingOptions is here.

like image 104
Bob Snyder Avatar answered Dec 07 '25 15:12

Bob Snyder