Skip to content

Instantly share code, notes, and snippets.

@shawnthye
Last active October 16, 2017 10:34
Show Gist options
  • Save shawnthye/4edd68c5611546d161f1a6c316694559 to your computer and use it in GitHub Desktop.
Save shawnthye/4edd68c5611546d161f1a6c316694559 to your computer and use it in GitHub Desktop.
Firebase Push Notification

Request

https://fcm.googleapis.com/fcm/send
Headers Value
Authorization key=<YOUR SERVER KEY>
Content-Type application/json

Request Sample

{
    "notification": { //iOS ONLY !!!important
        "title": "The notification's title.",
        "body": "The notification's body text.",
        "title_loc_key": "string_key", //key in strings on android/ios
        "title_loc_args": [
            "arg1",
            "arg2",
             ...
            "arg5"
        ],
        "body_loc_key": "string_key", //key in strings on android/ios
        "body_loc_args": [
            "arg1",
            "arg2",
             ...
            "arg5"
        ],
        "sound": "default"
    },
    "data": {
        "action": "ACTION", possible values ["SYNC_NOTIFICATIONS", "OPEN_WEB_CONTENT"]
        "url": null, // an url represent of this resource
    },
    "content_available": true,
    "collapse_key": "COLLAPSE_KEY", //ANDROID ONLY !!!important
    "registration_ids": [
        "fcm_token_1",
        "fcm_token_2",
         ...
        "fcm_token_10"
    ]
}

SYNC_NOTIFICATIONS Request for iOS

{
    "notification": {
        "title": "New property available",
        "body": "10+ new properties for sale from your recent search in Bangsar.",
        "title_loc_key": "notification_recent_search_properties_title",
        "title_loc_args": null,
        "body_loc_key": "notification_recent_search_for_sale_properties_body_template",
        "body_loc_args": ["10+", "Bangsar"],
        "sound": "default"
    },
    "data": {
        "action": "SYNC_NOTIFICATIONS",
        "notification_id": "NOTIFICATION_ID"
    },
    "content_available": true,
    "registration_ids": [
        "fCR4I4qSziQ:APA91bEawt65JID...",
        "e4rnMRD3ra4:APA91bFRyFcIFGZ...",
        "c2vIwV7yPVM:APA91bERNJdpJf7..."
    ]
}

SYNC_NOTIFICATIONS Request for Android

{
    "data": {
        "action": "SYNC_NOTIFICATIONS",
        "notification_id": "NOTIFICATION_ID"
    },
    "content_available": true,
    "collapse_key": "SYNC_NOTIFICATIONS",
    "registration_ids": [
        "fCR4I4qSziQ:APA91bEawt65JID...",
        "e4rnMRD3ra4:APA91bFRyFcIFGZ...",
        "c2vIwV7yPVM:APA91bERNJdpJf7..."
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment