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
asked 2 months ago145 views
1 Answer
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
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions