It is now possible to send push notifications from Azure Mobile Center.
One usual reason why we need to send notifications to our users is to encourage them to use the app on a regular basis. Obviously, in this scenario, we will not have a person whose job is to manually send notifications to each user from the portal. We need an automated process. So even though it’s possible to use the portal, it will be the work of our services to automatically send them.
Mobile application configuration
For this post I assume that you already have your application able to receive push notifications. Please note that Azure Mobile Center utilise Firebase (FCM) for Android and therefore we are perfectly up to date !
Here you will find instructions to correctly configure your apps :
- Xamarin iOS : https://docs.microsoft.com/en-us/mobile-center/sdk/push/xamarin-ios
- Xamarin Android : https://docs.microsoft.com/en-us/mobile-center/sdk/push/xamarin-android
- There are other documentations for different types of mobile apps, select one of the above links to choose your favorite platform.
One of the main assets for Azure Mobile Center is the very way it is developed. The Api developed before the web portal is added. It means that everything that can be done from the portal, can be done with the Api in REST !
The documentation for these APIs is available as a Swagger here https://docs.microsoft.com/en-us/appcenter/api-docs/ so it is possible to directly test them.
In order to access the Api you need to create an access token on https://mobile.azure.com/settings/apitokens. Store the created token in a safe place as you will never be able to see it again !
As I write these lines, the Push API is not documented in the correct place but in the Analytics part. At first, as I did not find it, I used CharlesProxy to analyse the generated network calls and as expected it was very easy to use the API this way !
Sending push notifications using Mobile Center API is very easy and convenient. As it is a REST based API, it is easy to add push to any webservice using any language.
Getting the user
In order to send push notifications you need to get your user name. For this, you just need to call the following service with a GET query
Getting the application
In order to send push notifications you need to get your application name. For this, you just need to call the following service with a GET query
Sending a push notification
Now that we have to necessary piece of information, sending a push notification is just a POST query on the right url :
The push request payload will be in json, so we need to add the correct HTTP header :
We just need to add the payload in the HTTP request’s body :
Now send it !
In this post we saw how to send a push notification to all the users of an application using Azure Mobile Center’s REST API. It is possible to filter these users be it is a story for another ti,e.
Today, my life as a developer became easy thanks to Azure Mobile Center. Don’t hesitate, like I do, to follow any Azure Mobile Center update because sometimes it is really worth your time :)