I'm trying to send a FCM from within a firebase function but I'm getting the following error every time:
await admin.messaging().sendToDevice(registrationToken, message)
I followed the suggestions from this post, of the same topic, no help. Pointing to Add the Firebase Admin SDK to your server, another link in the article, isn't very helpful as I am using Firebase Server.
This article, same, Sending FCM using Firebase Functions and I'm using the same code (the FCM code), same error.
This is the full error:
Error sending message: { Error: An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions. See https://firebase.google.com/docs/admin/setup for setup instructions. Raw server response: "<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
". Status code: 401.
at FirebaseMessagingError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:43:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:89:28)
at new FirebaseMessagingError (/workspace/node_modules/firebase-admin/lib/utils/error.js:255:16)
at Object.createFirebaseError (/workspace/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:57:12)
at /workspace/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:78:51
at process._tickCallback (internal/process/next_tick.js:68:7)
errorInfo:
{ code: 'messaging/authentication-error',
message:
'An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions. See https://firebase.google.com/docs/admin/setup for setup instructions. Raw server response: "<HTML>\n<HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Unauthorized</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n". Status code: 401.' },
codePrefix: 'messaging' }