API for Push Notifications

App Center follows the philosophy of API-first. You can expect API support for everything you see in the portal. We have a swagger as well as documentation on how to get started with our APIs.

Push API

Sending Push Notifications via API will allow you to automate the process of engaging with your users. Go to the Push Swagger to see the supported APIs.

Push Swagger

Note

In the Push API calls, "owner_name" could be either the app owner's user id, or the name of the org the app falls under.

Send notifications via API

In this documentation we will assume that you already have an app which is ready to receive push notifications. Follow our Push SDK documentation for the different supported platforms: Android, iOS, React Native Android, React Native iOS, UWP, Xamarin Android, Xamarin iOS, Xamarin Forms and macOS.

API Tokens

The first thing you will need to do is to create an API Token from your user settings, as shown in the image below.

Push API Token

User and Application

In order to send push notifications, you will need to get the user and the application name. To do so, you can use our APIs for the user and the application.

Here is an example on how to use this information to send push notifications:

https://appcenter.ms/api/v0.1/apps/<YOUR_USER_NAME>/<YOUR_APP_NAME>/push/notifications

Send the notification

You can send a push using this POST push API. The push request body is in JSON format (application/json content type). Here is an example:

{
 "notification_content" : {
  "name" : "First Push From App Center",
  "title" : "Push From App Center",
  "body" : "Welcome!",
  "custom_data" : {"key1" : "val1", "key2" : "val2"}
  }
}

Campaign

Campaign Name should be 64 characters or less, and title should be 128 characters or less. Otherwise you will get an error 400 Bad Request when sending the push via the API. To ensure you are within the limits, try constructing the name and title from the Campaign UI before pushing it via the API.

Send notifications to Audiences using API

Audiences allow you to segment your user base based on device and custom properties.

Define an audience

In order to define an audience using properties, you use the following symbols:

Definition Symbol Equivalent
equals = eq
not equals != ne
less than < lt
greater than > gt
less than or equal to <= le
greater than or equal to >= ge

Audiences based on device properties

You can send push to a group of users that match certain criteria (e.g. all users in United States). You can create groups (audiences) based on the device properties and custom properties. In order to create an audience you can use this PUT API.

Here is an example for an audiences based on a device property where country is United States:

{
  "definition" : "CarrierCountry eq 'US'",
  "description" : "Users in the United States"
}

Audiences based on custom properties

Here is an example for an audiences based 2 custom properties (boolean and string properties):

{
  "definition": "myBooleanProperty eq true and myStringPropety eq 'myStringValue'",
  "custom_properties": {
    "myBooleanProperty": "boolean",
    "myStringPropety": "string"
  }
}

You will need to add this custom properties using our SDK for each platform: Android, iOS, React Native, UWP, Xamarin and macOS.

Send push notification to an audience

{
 "notification_content" : {
  "name" : "First Push From App Center",
  "title" : "Push From App Center",
  "body" : "Welcome!",
  "custom_data" : {"key1" : "val1", "key2" : "val2"}
  },
    "notification_target" : {
    "type" : "audiences_target",
    "audiences" : ["a-1", "a-2"]
  }
}

Send notifications to Device IDs

This is an example of sending a Push Notifications to a set of Device IDs. To get the install ID, you can use our APIs: Android, iOS, React Native, UWP, Xamarin and macOS.

Below, you will find an example where we target the follwing devices IDs: 00000000-0000-0000-0000-000000000001,00000000-0000-0000-0000-000000000002, 00000000-0000-0000-0000-000000000003.

{
 "notification_content" : {
  "name" : "First Push From App Center",
  "title" : "Push From App Center",
  "body" : "Welcome!",
  "custom_data" : {"key1" : "val1", "key2" : "val2"}
  },
    "notification_target" : {
    "type" : "devices_target",
    "devices" : ["00000000-0000-0000-0000-000000000001","00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003"]
  }
}

Send notifications to all registered devices

This is an example of sending a Push Notifications to all registered devices.

{
 "notification_content" : {
  "name" : "First Push From App Center",
  "title" : "Push From App Center",
  "body" : "Welcome!",
  "custom_data" : {"key1" : "val1", "key2" : "val2"}
  },
    "notification_target" : null
}