It is maddening how well written and yet horribly organized Google's documentation is.
So first of all, if you find yourself here a year and a half later, .send()
is what you're looking for. It replaces .sendToDevice()
And here are the two links that have the actual docs/examples:
That said, and since the deprecated API is going to be removed from firebase any day now ("June of 2024"), I thought I would point out a glaring example of where the documentation here is sketchy.
So if you navigate to the docs page suggested by @Hiranya Jayathilaka, and scroll to the method in question and click on its name: sendToDevice() - you'll be taken to a page with this at the top:
Warning: This API is now obsolete.
And if you instead read its definition:
Sends an FCM message to a single device corresponding to the provided registration token. See Send to individual devices for code samples and detailed documentation. Takes either a registrationToken to send to a single device or a registrationTokens parameter containing an array of tokens to send to multiple devices.
If you follow the "Send to individual devices" link within said definition, you'll be taken to a page with this at the top:
Caution: Sending messages (including upstream messages) with the FCM XMPP and HTTP legacy APIs was deprecated on June 20, 2023, and will be removed in June 2024. If you are using the legacy FCM send APIs, we strongly recommend that you migrate to the HTTP v1 API or consider using the Admin SDK to build send requests.
If you navigate to the "Admin SDK" link at the end of that message you'll find yourself in the midst of an explanation of how to install/enable firebase messaging api for your google cloud project - near the end of which is:
... Then, once the Firebase Admin SDK is installed, you can start writing logic to build send requests.
If you navigate to that "build send requests" link, you'll find yourself right back where you started