Basically I want to be able to send a push notification for a specific registered device (using a tag) to the Azure Notification Hub which will then send that notification out to the device. I do have some c# code that will do this but I'd like to make use of an API if possible.
I found an article (computer restarted tho so I don't have the link) that explained how to send notifications using an API but it looks like it sends the notification to every device registered with the hub so I want to see if it would be easy to modify the body or even the pre-request script to include a specific device tag.
Or if any of you smart people know of an easier way to do this through an API then I'm all ears.
Here's my code (taken from Postman) that I currently have that's sending the notification to all hub devices.
POST endpoint: https://{namespace_name}.servicebus.windows.net/{hub_name}/messages/?api-version=2015-01
Headers:
- Authorization - {{azure-authorization}}
- Content-Type - application/json
- ServiceBusNotification-Format - gcm
Request body:
{"data":
{
"gcm.notification.body":"Hi",
"gcm.notification.title":"Hi",
}
}
Pre-request Script:
function getAuthHeader(resourceUri, keyName, key) {
var d = new Date();
var sinceEpoch = Math.round(d.getTime() / 1000);
var expiry = (sinceEpoch + 3600);
var stringToSign = encodeURIComponent(resourceUri) + '\n' + expiry;
var hash = CryptoJS.HmacSHA256(stringToSign, key);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
var sasToken = 'SharedAccessSignature sr=' + encodeURIComponent(resourceUri) + '&sig=' + encodeURIComponent(hashInBase64) + '&se=' + expiry + '&skn=' + keyName;
console.log(sasToken);
return sasToken;
}
postman.setEnvironmentVariable('azure-authorization', getAuthHeader(request.url,"DefaultFullSharedAccessSignature", "<full_shared_access_signature>"));
postman.setEnvironmentVariable('current-date',new Date().toUTCString());