5
votes

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

1 Answers

31
votes

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