Early I had a chance to test FCM service sending request through Postman
https://android.googleapis.com/gcm/send
Header:
"key":"Content-Type","value":"application/json"
"key":"Authorization","value":"key=AIzaSyAA-XXXXXXXXXXXXXXXXXXXX"
Body:
{
"registration_ids":["token_id"],
"data": {
"title" : "title",
"message" : "This is something you might be interested in"
}
}
But now I receive such kind of response
{
"multicast_id": 6211560223995368844,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidRegistration"
}
]
}
Is there anybody could help me to fix my issue. I want to send Push Notification with Data payload and without Notification payload(I couldn't do it through Firebase console because it sends only not null Notification)
Related
I am trying to create a post request for sending firebase push notifications (trying on postman) and I am getting MismatchSenderId:
{
"multicast_id": 4548549053367743061,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "MismatchSenderId"
}
]
}
I have sender id from firebase console:
But i dont know how to put it in my starting request which is like this:
{
"to": "************************ server Key from firebase project settings",
"message":{
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
}
}
And headers look like this:
I am trying to send an FCM message to a topic. But getting "Invalid topic value provided" error from the server.
Json Payload
{
"message":{
"topic":"/topics/news",
"data":{
"title":"Hellow World",
"message":"This is the Topic Message",
"type1":"100",
"type2":"abc"
}
}
}
Response
{
"error":{
"code":400,
"message":"Request contains an invalid argument.",
"status":"INVALID_ARGUMENT",
"details":[
{
"#type":"type.googleapis.com/google.rpc.BadRequest",
"fieldViolations":[
{
"field":"message.topic",
"description":"Invalid topic value provided."
}
]
},
{
"#type":"type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode":"INVALID_ARGUMENT"
}
]
}
}
I have tried topic value as "news" (without '/topics/') but it throws same error. I can send message to the topic from firebase console without any problem.
Any help appreciated. TIA
Edit1 - Notification payload below works fine but data payload doesn't work. As per documentation, data payloads too are allowed https://firebase.google.com/docs/cloud-messaging/android/topic-messaging
Request
{
"message":{
"topic" : "foo-bar",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
}
EDIT2 :
This works. I had a small bug in my code which was adding additional quotes to the topic. Below request works like a charm
{
"message":{
"topic":"news",
"data":{
"title":"Hellow World",
"message":"This is the Topic Message",
"type1":"100",
"type2":"abc"
}
}
}
according to doc yor request should be like this:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
I am sending a push token to a specific device via the FCM API on testing with Postman, but I intend to send them from the server.
{
"to" : "my_device_token",
"notification" : {
"notificationTitle" :"test from server",
"notificationBody" :"test lorem ipsum"
}
}
I am receiving the response
{
"multicast_id": 4996861050764876123,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results":
[
{
"message_id": "0:1519567530487886%f95ee7d4f95ee123"
}
]
}
Which shows no error, however I don't get any notifications on my phone.
I tried the same device token using on firebase website "Notifications => New Message => Single Device", and it works.
I see threads about not receiving the notifications when the app is not running, however I don't get any even if the app is running.
Edit: My application is built using Xamarin.Android, if relevant.
The notification property keys are title and body:
{
"to" : "my_device_token",
"notification" : {
"title" :"test from server",
"body" :"test lorem ipsum"
}
}
See Table 2b in the documentation.
I am sending push in a single devices using via FCM api. The JSON is given below.
In the case of Android
{
"to" : "device Tokens", // Your android device token
"data" :
{
"body" : "test",
"title" : "test",
"pushtype" : "events",
};
In the case of IOS json
{
"to" : "device Tokens", // iphone tokens
"data" :
{
"body" : "test",
"title" : "test",
"pushtype" :"events",
},
"notification" : {
"body" : "test",
"content_available" : true,
"priority" "high",
"title" = "C#"
}
} ;
put in index.js
PushNotification.configure({
onNotification: function (notification) {
console.log("NOTIFICATION:", notification);
},
requestPermissions: Platform.OS === 'ios'
})
in your screen
createChannels =()=>{
PushNotification.createChannel(
{
channelId:"test-channel",
channelName:"Test-channel"
}
)
}
handleNotification=()=>{
PushNotification.localNotification({
channelId:"test-channel",
title:"Kinza ",
message: "hi gow adww biy",
});
PushNotification.localNotificationSchedule({
channelId: "test-channel",
title:"Alram",
message:"Hi how are you",
date: new Date(Date.now() + 20*1000),
allowWhileIdle:'true',
});
}
I setup a REST client with POST --> https://fcm.googleapis.com/fcm/send
Content-Type : application/json
Authorization : key=<server-key>
JSON Body:
{
"to": "testTopic",
"data": {
"key1" : "val1",
"key2" : true
}
}
The repsonse in 200 OK but the response body has:
{
"multicast_id": 6098503498585,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results":[
{
"error": "InvalidRegistration"
}
]
}
So the onMessageReceived() is not triggered, neither app in foreground nor in background? Why do I get InvalidRegistration ? What am I missing?
The server key at point 3 is from Firebase Project settings --> Cloud messaging --> Server key
In 4. your JSON requires a preceeding
/topics/
for "to" thus:
{ "to": "/topics/testTopic",....}
I make a request to https://fcm.googleapis.com/fcm/send with the following json data:
{
"to": "/topics/push_topic",
"data" : {
"language": "tr,en_us",
"ticker": "...",
"tickerEnglish": "...",
"body": "...",
}
}
The response I receive is the following (The message is sent successfully):
{
"message_id": xxxxxxxxxxxxx
}
But according to the documentation, I am supposed to receive a response like the following:
{
"multicast_id": 216,
"success": 3,
"failure": 3,
"canonical_ids": 1,
"results": [
{ "message_id": "1:0408" },
{ "error": "Unavailable" },
{ "error": "InvalidRegistration" },
{ "message_id": "1:1516" },
{ "message_id": "1:2342", "registration_id": "32" },
{ "error": "NotRegistered"}
]
}
So, why can't I see success and failure variables in my response? Is that because I send the message to a topic?
Thanks.
This is the expected response when sending to a topic.
The sample response with multiple results is for when you are using the registration_ids parameter when sending the message payload.