Firebase Push notification is not playing sound when using cURL https://fcm.googleapis.com/fcm/send

When I use the Firebase console, everything is perfect by activating "Sound" under the "Advanced options" as explained by the best answer Mouad Abdelghafour AitAli wrote in the accepted answer at Firebase Push notification is not playing sound when app is in background. When I use cURL making the request to the endpoint https://fcm.googleapis.com/fcm/send, I receive the notification and the only problem is that the notification does not play the sound. This is how I am sending the notification from the command prompt:

C:\curl>curl -k -X POST --header "Authorization: key=<My authorization key>" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"<Token of device that receives the notification>\",\"notification\":{\"body\":\"Yellow\"},\"priority\":10,\"sound\":\"default\"}"
{"multicast_id":4910170660116070247,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1512975815064180%efad4c69efad4c69"}]}

Notice how I am using \"sound\":\"default\", but the notification is still not playing the sound. It works from the Firebase console as I mentioned, so I am trying to understand why it does not work using cURL from the command line. Thank you.

1 answer

  • answered 2017-12-11 07:17 Jaime Montoya

    I had the parameter \"sound\":\"default\" in the wrong place. I fixed it by using this the following code, and I received the notification with the default sound playing for this notification:

    C:\curl>curl -k -X POST --header "Authorization: key=<My authorization key>" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"<My device token>\",\"notification\":{\"body\":\"Yellow\",\"sound\":\"default\"},\"priority\":10}"
    {"multicast_id":6830402283642572741,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1512977917758257%efad4c69efad4c69"}]}