What's new with FCM? Customizing messages across platforms!

What is FCM?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that reliably delivers messages at no cost. FCM sends over 400 billion messages per day. Today we are excited to announce the launch of a new RESTful API, the FCM HTTP v1 API, that makes it safer and easier to send messages to your cross-platform applications. All existing FCM clients can receive messages sent via the new FCM API — it does not require any changes on the client side.

Why a new FCM API?

Security

The new FCM API uses the OAuth2 security model. In the event that an access token becomes public, it can only be used for an hour or so before it expires. Refresh tokens are not transmitted as often and are thus much less likely to be captured.

Cross Platform Support

Sending messages to multiple platforms is possible with the legacy API. However, as you add functionality to messages, sending to multiple platforms becomes difficult. With the new FCM API, sending messages to multiple platforms is very easy.

You can still send simple messages to multiple platforms using the common top level fields. For example, you can send this message informing users about a sale:

{
  "message": {
     "topic":"sale-watchers",
     "notification": {
       "title":"Check out this sale!",
       "body":"All items half off through Friday"
     }
}

When you send a notification like this one to devices subscribed to a topic, you probably want them to be taken to the description of the item. On Android you would compose a message including a "click_action" field indicating the activity to open. On iOS, APNs relies on a "category" indicating the action to take upon clicking, including which view to show.

Before, since these keys were unique to their respective platforms, developers would have to create two separate messages. Now, we can use platform-specific fields together with common ones in a single message:

{
  "message": {
     "topic":"sale-watchers",
     "notification": {
       "title":"Check out this sale!",
       "body":"All items half off through Friday"
     },
     "android":{
       "notification"{
         "click_action":"OPEN_ACTIVITY_3"
       }
     },
     "apns": {
       "payload": {
         "aps": {
           "category": "SALE_CATEGORY"
         }
       }
     }
   }
 }

Note: In this case web apps subscribed to the ‘sale-watchers’ topic will receive a notification message with the defined title and body.

Extendable

The new FCM API fully supports messaging options available on iOS, Android and Web. Since each platform has its own defined block in the JSON payload, we can easily extend to other platforms as needed. If a future IoT messaging protocol requires a security_key field we could easily support an iot block within the FCM payload.

{
  "message": {
     "topic":"sale-watchers",
     "notification": {
       "title":"Check out this sale!",
       "body":"All items half off through Friday"
     },
     "android":{
       "notification"{
         "click_action":"OPEN_ACTIVITY_3"
       }
     },
     "apns": {
       "payload": {
         "aps": {
           "category": "SALE_CATEGORY"
         }
       }
     }
     "iot": {
       "security_key": "SECURITY_KEY"
     }
   }
 }

Learn more

The new FCM API is the more secure, cross platform, future proof way of sending messages to FCM clients. If you are currently using the FCM legacy API, or if you are interested in using FCM to send messages to your apps, give the new FCM API a try. See the FCM guides and reference docs for more.