question

SekarSivaramanCognizant-9884 avatar image
0 Votes"
SekarSivaramanCognizant-9884 asked ·

Unable to register device to azure notification hub using nodejs packages.

We are trying to send push notification dynamically to all registered devices (android) using azure push notification. when we are trying to register the device using device token received from flutter mobile app. it is not getting registered.

For reference: https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-nodejs-push-notification-tutorial

In the above documentation, there is no step to register device using their device token to notification hub. So tried to check on some tech forums and got a sample way to proceed on registering device. Code is below for reference.
Code Snippet:

notificationHubService.gcm.createTemplateRegistration(
'replacing device token',
'tag', {
'aps': {
'alert': '$(message)',
'badge': '#(count)',
'sound': 'default'
}
},
function (e, r) {
if (e) {
console.log(e);
} else {
console.log({
id: r.RegistrationId,
deviceToken: r.DeviceToken,
expires: r.ExpirationTime
});
}
}
);


Response:

{
id: '1294571364808236565-5460521645299605787-1',
deviceToken: undefined,
expires: '9999-12-31T23:59:59.999'
}

device token is always returning as undefined.

azure-notification-hubs
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

brtrachMSFT-0711 avatar image
0 Votes"
brtrachMSFT-0711 answered ·

@SekarSivaramanCognizant-9884 We apologize for the error you are encountering when attempting to register the devices.

Please see this sample of how to use the Azure-SB SDK here

Using this example, you can set the GCM_REGISTRATION_ID which is the device token from the Android device such as you would get from here.

This has the usage of GCM/Firebase here in registering, which is using the REST-API method of create registration under the covers: Create a registration | Microsoft Docs

Can you please review this content to see if this allows you to successfully register the device?


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.