I am writing a new server application (using .net) to send notifications to clients (mainly android devices), and I am using the new Http v1 api from firebase cloud messaging, I saw the following Post request body to send a notification for topics
{
"message": {
"topic": "news",
"notification": {
"title": "Breaking News",
"body": "New news story available."
},
"data": {
"story_id": "story_12345"
}
}
}
However how am I going to send a notification to specific device using FCM Id ?
Note: I had already implemented sending notification to single device using the legacy API.
There is documentation for the v1 HTTP API. Specifically, there is a section for sending messages to a specific device. You need to know the device token:
{
"message":{
"token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification": {
"title": "Breaking News",
"body": "New news story available."
},
"data": {
"story_id": "story_12345"
}
}
Related
So i have a chat app and i want it so that i can get a notification once someone sends me a message. The thing is that i implemented firebase messaging and i can receive a notification if i send it from firebase. I want to add it such as once i press the send button i can directly send the notification to a token within the app for instance something like:
send notification{
to token : here the receiver token
title : the title of the notification
description : the description of the notification
}
is it possible to have something like this?
Just for helping,
If anyone wants to use REST POST API, here it is, use the Postman with below configuration
URL:
https://fcm.googleapis.com/fcm/send
Header:
"Content-Type": "application/json",
"Authorization": "key=<Server_key>"
BODY:
{
"to": "<Device FCM token>",
"notification": {
"title": "Check this Mobile (title)",
"body": "Rich Notification testing (body)",
"mutable_content": true,
"sound": "Tri-tone"
},
"data": {
"url": "<url of media image>",
"dl": "<deeplink action on tap of notification>"
}
}
I wrote google translator. Please understand this part.
hi.
There was a problem when upgrading the API version from FCM HTTP to FCM HTTP v1.
FCM HTTP v1 API request was made through POSTMAN.
Below is the sending message body.
{
"message": {
"topic": "this_is_test_topic",
"data": {
"body": "1234567890"
},
"android": {
"priority": "high"
}
}
}
When I made the above request, IOS client received it normally even though it was sent once or twice per second.
However, the ANDROID client did not receive a message from FCM for a certain period of time after receiving the first 20 times.
The message could be transmitted once more after a certain time.
This was the same as the limitations of compact messages in the FCM documentation.
Link: https://firebase.google.com/docs/cloud-messaging/concept-options?hl=en#collapsible_throttling
However, I didn't put any data related to the miniature in the message I sent.
If you make a request to the existing FCM HTTP with the same topic, data is received normally. Below is the corresponding code.
{
"to": "this_is_test_topic",
"data": {
"body": "1234567890"
}
}
If the FCM HTTP v1 API is requested using the same topic and token instead of topic, data is received normally. Below is the corresponding code.
{
"message": {
"token": "asdkjasldjalksdjlk*******************",
"data": {
"body": "1234567890"
},
"android": {
"priority": "high"
}
}
}
all request response status code is 200
I'm trying to send a push notification via REST API Firebase by Postman for specific user I followed below request pattern:
POST request with below URL :
https://fcm.googleapis.com/fcm/send?key=**my Web API key**
and the Body is
{ "data":
{
"title": "Firebase notification",
"detail": "I am firebase notification. you can customise me. enjoy"
},
"to" : "USER UID"
}
but the problem is it returns The request was missing an Authentication Key.
Kindly follow the steps as per bellow :
API URL: https://fcm.googleapis.com/fcm/send/
Request Method Post
Add 2 Key-value pairs in Header section like this
Content-Type : application/json
Authorization: key=[Your server key] (Make sure that no space allowed)
For body choose raw data (JSON)
{ "data": { "title": "Firebase notification", "detail": "I am firebase notification. you can customise me. enjoy" }, "to" : "USER UID" }
I'm trying to send a notification using firebase api and the notification is sent successfully if I only have "title" and "body" in the notification JSON object. However, if I add "sound":"default" to the notification object, as described in the documentation, I get the following error:
"Invalid JSON payload received. Unknown name \"sound\" at 'message.notification': Cannot find field."
My JSON object is as follows:
{"message":{"token": token, "notification":{"title":"Test", "body":"Test message from server", "sound":"default"}}}
The appearance of message in your JSON indicates you are using the HTTP v1 API. The documentation you linked is for the legacy API.
The HTTP v1 API JSON to send a notification with sound for Android and iOS devices should be:
{
"message": {
"token": "your-token-value",
"notification": {
"title": "Test",
"body": "Test message from server"
},
"android": {
"notification": {
"sound": "default"
}
},
"apns": {
"payload": {
"aps": {
"sound": "default"
}
}
}
}
}
I successfully configured and connected Safari Web Push. When sending request through the REST api I get a successful code 202 but the push notification does not received by Safari browser.
For Safari web push notification you need to pass all the optional settings when you are sending the notification. For example:
{ "message": { "alert": "Safari Web Notification with icon and title for registered devices ", "url": "www.ibm.com" }, "settings" : { "safariWeb": { "title": "Flight A998 Now Boarding", "body": "Boarding has begun for Flight A998.", "action": "View", "urlArgs": ["www.google.com"] } }, "target":{ "platforms":["WEB_SAFARI"] } }