Batch send notifications to device tokens using Notification Hubs

Posted on 13 June, 2016

Program Manager, Azure App Service

We are excited to announce the Batch Direct Send feature for our Basic and Standard tiered customers. This is a batch version of the previously published Direct Send feature, which enabled sends to individual device tokens/channel uris. Since this feature doesn't require devices to be registered with Notification Hubs, customers can now utilize their hubs as scalable push engines at their convenience, simplifying custom device storage and migration scenarios.

The feature is available through REST, and a sample WNS batch direct send payload would look like the following:

// note that the empty line breaks in this payload are mandatory
const string payload = @"
Content-type: text/xml
Content-Disposition: inline; name=notification

<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from Batch Direct Send!</text></binding></visual></toast>
Content-type: application/json
Content-Disposition: inline; name=devices


The request in .NET would look similar to the following:

var uri = new Uri("" + myHubName + "/messages/$batch?direct&api-version=2015-08");
var sendRequest = WebRequest.CreateHttp(uri);
sendRequest.Method = "POST";
sendRequest.ContentType = @"multipart/mixed; boundary = ""simple-boundary""";
sendRequest.Headers["Authorization"] = GenerateSasToken(uri);
sendRequest.Headers["ServiceBusNotification-Format"] = "windows";
sendRequest.Headers["X-WNS-Type"] = "wns/toast";

Try it out and let us know what you think! If you are new, check out our Notification Hubs service and documentations.