0

I am sending a web request to Firebase Cloud Messaging to send a message. The raw data as sent with Content-Type:application/json" is:

{ "to":"ecO8y..._D", "data": [ {"msisdn":"+1111111" }, {"b":"c"} ] }

Firebase responds with this error message:

Field "data" must be a JSON array: [{"msisdn":"+1111111"},{"b":"c"}]

Is there something wrong with the text that I have entered for the data field?

2 Answers 2

1

I think the "JSON array" wording is confusing here. The data needs to be a JSON object with a single level of properties, so:

{
  "to":"ecO8y..._D", 
  "data": {
    "msisdn":"+1111111", 
    "b":"c"
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, data can't have hierarchical data or array of elements. It can contain only one level child elements.
0

When you try to send data from your application server to FCM, you will get 400 error, if data element contains hierarchical data or array of elements.

Data with one level of child element works.

{"message":{"topic":"users","data":{"name":"srao","pho":"38743"}}}

Data with array of element doesn't work.

{"message":{"topic":"users","data":[{"name":"grag","pho":"38743"},{"name":"boney","pho":"3899943"}]}}

Data with multiple levels or hierarchy doesn't work.

 {"message":{"topic":"users","data": {"person" : {"name":"srao","pho":"38743"}}}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.