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

Sekar, Sivaraman (Cognizant) 1 Reputation point
2021-03-16T09:04:43.747+00:00

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://learn.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
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
295 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 15,786 Reputation points Microsoft Employee
    2021-03-17T02:18:09.767+00:00

    @Sekar, Sivaraman (Cognizant) 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 Learn

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

    0 comments No comments