Firebase Cloud Messaging sound error - firebase

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"
}
}
}
}
}

Related

How to achieve time-sensitive flag in APNS JSON output via FCM?

iOS distinguishes between messages by UNNotificationInterruptionLevel. I would like to achieve that messages sent via FCM have the time-sensitive interruption-level.
Is this equivalent to just sending messages in FCM with high priority? Unfortunately it's not super clear to me from looking at the docs.
The interruption level is automatically handled by system, not by FCM. That's different than the high priority.
You should be able to use it as it is by following Apple's documentation. FCM supports passing down the interruption-level in the payload.
I achieved this by having this payload in my firebase console file:
var message = {
notification: {
title: "Notification Title",
body: `${initiatedUsername} sent you message`,
},
"data": {
"target_exec":"messaging"
},
"apns": {
"payload": {
"aps": {
"alert": {
"title": "Notification Title",
"body": `${initiatedUsername} sent you a message`
},
"badge": 1,
"sound": "default",
"interruption-level": "time-sensitive"
}
}
},
token: fcmToken,
};
You can change the token attribute to topic aswell, if you'd rather like to send a message to a topic.
Hope this might help somebody out here!

Flutter send firebase notification to token

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>"
}
}

When using fcm http v1, data messages do not arrive normally after about 20 times

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

The request was missing an Authentication Key with push notification in firebase

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" }

Send messages to specific devices using new firebase API

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"
}
}

Resources