I tried to configure node js server with firebase fcm cloud messaging and when i try to send message i have response from server:
FirebaseMessagingError: An unknown server error was returned. Raw server response: ""DeprecatedApi""
at FirebaseMessagingError.fromServerError (/usr/src/app/node_modules/firebase-admin/lib/utils/error.js:269:16)
at /usr/src/app/node_modules/firebase-admin/lib/messaging/messaging.js:94:65
at Array.forEach (<anonymous>)
at mapRawResponseToDevicesResponse (/usr/src/app/node_modules/firebase-admin/lib/messaging/messaging.js:90:26)
at /usr/src/app/node_modules/firebase-admin/lib/messaging/messaging.js:484:24
i use the latest “firebase-admin”: “12.4.0”, on the firebase console i enable only “Firebase Cloud Messaging API (V1)” and i use generated json with credentials to initialize app:
const firebaseAdmin = require('firebase-admin');
const firebaseApp = firebaseAdmin.initializeApp (
{
credential: firebaseAdmin.credential.cert ({
type: 'service_account',
project_id: ...,
private_key_id: ...,
private_key: ...,
client_email: ...,
client_id: ...,
auth_uri: 'https://accounts.google.com/o/oauth2/auth',
token_uri: 'https://accounts.google.com/o/oauth2/token',
auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs',
client_x509_cert_url: ...
}),
databaseURL: ...,
},
'app'
);
firebaseApp.messaging().sendToDevice(
tokens,
{
notification: {...},
data: {...}
}
);
and as a result of the sendToDevice i have error mentioned above.
What i missing or doing wrong?
2
Solution :
The sendToDevice method is deprecated; Google now recommends using the send method instead.
The send method has been available since SDK version 6.0.0
Example usage:
const message = {
notification: {
title: title,
body: body,
},
data: {
title: title,
},
token: pushToken
};
await firebase.messaging.send(message);
More information :
Below are the details regarding the new methods using Google’s HTTP v1 API for messaging. This information is provided to help you transition to the new method using API v1:
Source click here