Invalid topic value provided - While sending FCM to a topic

Multi tool use
Invalid topic value provided - While sending FCM to a topic
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"
}
}
}
1 Answer
1
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!",
}
}
using request format you have mentioned gives error - "Invalid JSON payload received. Unknown name "to": Cannot find field.nInvalid JSON payload received. Unknown name "data": Cannot find field.",
– Saket
Jul 3 at 8:57
try this: { "to": "/topics/news", "data": { "title":"Hellow World", "message":"This is the Topic Message", "type1":"100", "type2":"abc" } }
– Omid Ziyaee
Jul 3 at 9:04
Nope doesn't work. same error Unknown name "to".
– Saket
Jul 3 at 9:31
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I am referring this. firebase.google.com/docs/cloud-messaging/android/… Can you please fix the link in your comment. Thanks
– Saket
Jul 3 at 8:36