AWS SNS with FCM: Notification body is invalid

0

I'm unable to send a test SNS using FCM. I have setup my platform application to use FCM and a token. I get the following error message when I attempt to send a test message to one of my endpoints using the console:

{"DeliveryAttempts":1,","EventType":"DeliveryFailure","FailureMessage":"Notification body is invalid","FailureType":"InvalidNotification","Service":"SNS","Time":"2024-03-07T18:59:46.489Z"}

I attempted the following message types:

  • Just raw text
  • JSON:

{ "GCM": "{ "data": { "message": "Sample message for Android endpoints" } }" }

and

{ "GCM":"{ "notification": { "body": "Sample message for Android or iOS endpoints", "title":"TitleTest" } }" }

None of these appear to work. What is the correct way to format the body for FCM?

Sending a test message to my phone from Firebase is working.

fnllc
已提問 3 個月前檢視次數 173 次
1 個回答
0

The error message "Notification body is invalid" typically occurs when the payload you're sending is not properly formatted according to the Firebase Cloud Messaging (FCM) protocol.

Here's the correct format for sending a notification to FCM via AWS SNS:

{
  "GCM": "{\"notification\":{\"body\":\"This is a notification message for FCM!\",\"title\":\"FCM Message\"}}"
}

If you want to send data payload instead of a notification, you can use the following format:

{
  "GCM": "{\"data\":{\"message\":\"This is a data message for FCM!\"}}"
}

Test the setup

  1. Go to SNS console and open the platform application.
  2. Select the endpoint and choose “Publish message”.
  3. Select “Custom payload for each delivery protocol” and add the above message body.
AWS
已回答 3 個月前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南