Firebase Cloud Messaging (FCM) setup for push notifications
Before you can send push notifications, you must:
- Generate and import your FCM server key.
- Configure push in your app by writing code to identify your users and send them to Dynosend, alongside with their device token.
Firebase Cloud Messaging (FCM) setup
To send notifications through Firebase Cloud Messaging, you’ll need to upload a JSON server key. If you already have your key, you may skip ahead to step 4.
- Log into the Firebase Console for your project.
- Click the clog icon in the sidebar and go to Project settings.
- Go to Service accounts and click Generate new private key. Then click on Generate key
- In Dynosend, go to Channels, select Mobile push and click on Add project. Give your project a name (your application's name for example) and create the project.
- Now click on the new created project, and drag your server key JSON file to upload it. When you're done, you'll be ready to register new devices and send notification.
How to register device tokens
To register a device, you first need to make sure that your user is a contact in a Dynosend audience. Then you can simply send an API call whenever the user opens the app to generate a device token and send it to Dynosend.
It is recommended to use this method to identify contacts by their own unique UID.
bash
curl -X POST https://api.dynosend.com/device/register \ -H "Content-Type: application/json" \ -d '{ "app_id": "your_app_id", "contact_uid": "the_contact_uid", "fcm_token": "the_device_token", "platform": "the_device_platform" // android or iOS (optional) }'
Alternatively, you can identify contacts by email address, in which case you must also specify the UID of the audience the contact belongs to.
bash
curl -X POST https://api.dynosend.com/device/register \ -H "Content-Type: application/json" \ -d '{ "app_id": "your_app_id", "email": "user@example.com", "audience_uid": "your_audience_uid", "fcm_token": "the_device_token", "platform": "the_device_platform" // android or iOS (optional) }'
You do not need to authenticate the API call with your API key.