As per firebace doc, we can send FCM data messages in below format:
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMEFQ3P1...",
"data":{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}
}
}
But, I am required to send data as JSON Array like below:
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoIZvvDMExUdFQ3P1...",
"data":{
"geofence":[{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
},
{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}]
}
}
}
I am getting below error if I try to send JSON Array in request body for sending messages:
Unable to send message to Firebase:
{ "error":
{ "code": 400,
"message": "Invalid value at 'message.data[0].value' (Map), Cannot have repeated items ('geofence') within a map.\nInvalid JSON payload received. Unknown name \"\" at 'message.data[0].value': Proto fields must have a name.",
"status": "INVALID_ARGUMENT",
"details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "field": "message.data[0].value", "description": "Invalid value at 'message.data[0].value' (Map), Cannot have repeated items ('geofence') within a map." }, { "field": "message.data[0].value", "description": "Invalid JSON payload received. Unknown name \"\" at 'message.data[0].value': Proto fields must have a name." } ] } ]
}}
Android code is expecting data in JSON Array format not in String. I am stucked here badly.
Any help will be highly appreciated.
The values in the data payload must be strings. You can't have arrays or objects. Your geofence is an array.
You can see from the Android API for RemoteMessage.getData() that the return type is Map<String, String>
, which implies that you can only have string values. You can see also in the protocol docs that the data payload is string keys mapped to string values. So, you're going to have to figure out a way to flatten your data to strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With