HenrikP HenrikP - 4 years ago 202
C# Question

Azure Notifications hub format tags payload REST API

I have an ordinary C# MVC website that is connected to a database were I'm storing my phone apps Push IDs.

I take these push IDs and want to send a push to it.
I can do this manually with the send test push function on Microsoft Azure website by inserting the value into the tag field there.

But now I want to do it with the REST API from my website.

I followed this for the .NET example


The payload for Android looks like this:

{\"data\":{\"message\":\"" + message + "\"}}

I tried adding the tags to the payload by doing this:

{\"data\":{\"message\":\"" + message + "\"}, \"tags\":{\"DeviceToken\":\"the push ID here\"}}

But it didn't work. The push got sent to everyone.

How do you use or format the tags in the REST API?


headers.Add("ServiceBusNotification-Tags", recipient);

recipient in my case is the installationID

Answer Source

According to your description, I checked the REST API Send a GCM Native Notification and followed azure-notificationhubs-samples to test this issue. In order to add tags to your payload, you could specify ServiceBusNotification-Tags header. I sent a GCM native notification to a set of tags (game, news), you could refer to it:

Additionally, you could leverage Microsoft.Azure.NotificationHubs for sending push notifications. For more details, you could refer to this official document.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download