I am trying to send Azure push notification to android devices by using Postman. To achieve this i saw post in microsoftDocs but docs saying that This API doesn't support Firebase Cloud Messaging (FCM) yet. Is there any way to send FCM push notification from postman by using MsAzure
Finally i got the solution
URL
https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/?api-version=2015-01
Parameter
Headers
Authorization {{azure-authorization}}
Content-Type application/json
ServiceBusNotification-Format gcm
Body (Body will be according to you. No need to maintain as below)
{"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);
alert(sasToken);
return sasToken;
}
postman.setEnvironmentVariable('azure-authorization', getAuthHeader(request.url,"DefaultFullSharedAccessSignature", "xxxxxxxxxxxxxxxxxxxxxx"));
postman.setEnvironmentVariable('current-date',new Date().toUTCString());
In the above code (Pre-request Script) we have to update DefaultFullSharedAccessSignature for that follow the below steps
Go to Azure portal | Access Policies | Copy the DefaultFullSharedAccessSignature and paste some where | from there copy the SharedAccessKey
Images for reference