firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Deprecated legacy messaging methods are still available

Open enixsoft opened this issue 1 year ago • 6 comments

Describe your environment

  • Operating System version: Ubuntu 22.04.4 LTS
  • Firebase SDK version: v12.1.1
  • Firebase Product: messaging
  • Node.js version: v20.12.2
  • NPM version: 10.5.0

Describe the problem

According to FAQ for FCM features deprecated in June 2023, the API endpoint https://fcm.googleapis.com/fcm/send is shutting down and:

Requests to the endpoint will start failing after 6/21/2024.

It has been replaced by HTTP v1 endpoint: https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

However, in this latest v12.1.1 version of firebase-admin-node, there are 4 methods still using this legacy endpoint:

Only methods sendToDevice and sendToDeviceGroup are marked as deprecated, but methods sendToTopic and sendToCondition are not - despite all of them using the same endpoint. But won't all four of them stop working soon? So shouldn't they have been already removed in the latest version? It is a breaking change.

enixsoft avatar Jun 18 '24 13:06 enixsoft

These are now throwing Error sending to topic FirebaseMessagingError: An unknown server error was returned. Raw server response: "{"error":"Deprecated endpoint, see https://firebase.google.com/docs/cloud-messaging/migrate-v1"}"

Johnnyrook777 avatar Aug 14 '24 04:08 Johnnyrook777

Yes @Johnnyrook777 for me as well. sentToTopic is an important one for our business and now not working anymore. I am using v 12.3.1.

DevDianDankie avatar Aug 14 '24 06:08 DevDianDankie

If I look here the example seems to indicate that the new send method will also handle topics?

https://firebase.google.com/docs/cloud-messaging/migrate-v1#update-the-payload-of-send-requests

I am going to update and test and refer back here if it was successful or not

DevDianDankie avatar Aug 14 '24 06:08 DevDianDankie

Yes using .send() instead of sendToTopic() works. sendToCondition will probably also work as it can take the message type is:

export type Message = TokenMessage | TopicMessage | ConditionMessage;

DevDianDankie avatar Aug 14 '24 06:08 DevDianDankie

Yes, .send() works fine as a replacement, but the issue is that those deprecated methods that no longer work are still present in the latest version (now 12.3.1) and some aren't even marked as deprecated. It seems developers here simply doesn't care even though notifications are essential to many apps.

enixsoft avatar Aug 14 '24 07:08 enixsoft

Thanks @DevDianDankie, I also had success using a TopicMessage and .send.

Seems like an oversight to not have the old functions migrated or depicated, and we certainly got caught off guard :(

Johnnyrook777 avatar Aug 14 '24 21:08 Johnnyrook777

I think this is solved by https://github.com/firebase/firebase-admin-node/pull/2683

jhb-dev avatar Aug 30 '24 10:08 jhb-dev

Hey folks, sendToTopic and sendToCondition should have been marked as deprecated along with the other deprecated FCM APIs. We missed it. I apologies for the confusion this caused. The APIs are now deprecated in v12.4.0+

Please use the send() API instead.

Send messages to topics

lahirumaramba avatar Aug 30 '24 17:08 lahirumaramba

I'm using quite old version, but my app is working! "firebase-admin": "^11.2.0"

and getting this error: Deprecated endpoint, see https://firebase.google.com/docs/cloud-messaging/migrate-v1\

while using this method:

// Send message const response = await admin.messaging(app).sendToDevice( user.mobileData.mobileToken, message, { priority: 'high', timeToLive: 60 * 60 * 24 } );

UBT-FJ avatar Sep 15 '24 13:09 UBT-FJ

You have to change from:

fcm.send(message, function (response) {
						let parsed = JSON.parse(response);
						if (parsed) {
							console.log('Something has gone wrong!', parsed);
							console.log(parsed.failure);
							if (parsed.failure === 1) {
								db.doc(`fcmtokens/${recipient}`).delete();
							}
						}
					});

To using the Admin SDK as so:

messaging.send(message)
						.then(() => {
							console.log('Push notification sent succesfully.');
						})
						.catch((err) => {
							console.log('ERROR PUSH', err);
						});

and from the notification object change the "to" key to "token"

{to: FCM_TOKEN //old way,
token: FCM_TOKEN }

CalvinJamesHeath avatar Sep 18 '24 20:09 CalvinJamesHeath

aw

willysilalahi avatar Nov 08 '24 09:11 willysilalahi