0

Azure Notification Hub Exception: not able to register device entries.. the request could not be completed. we are using node js to register

  • If my solution inspires or helps you, please mark my answer as [accepted](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) , Tks~ – Jason Pan Jan 27 '21 at 02:23
  • it seems the issue is related to SSL handshaking.. – deepak patil Jan 27 '21 at 09:59
  • Does `NotificationHubClient.SendFcmNativeNotificationAsync` throw exception? [Azure Notification Hub Exception: Could not create SSL/TLS secure channel](https://learn.microsoft.com/en-us/answers/questions/232661/azure-notificaiton-hub-exception-could-not-create.html) – Jason Pan Jan 28 '21 at 03:46

2 Answers2

0

You can use below code to register device entries.

Related posts and documents:

1. Issue with notification hub

2. createRegistrationId(callback)

/**
* Creates a registration identifier.
*
* @param {Function(error, response)} callback      `error` will contain information
*                       if an error occurs; otherwise, `response`
*                       will contain information related to this operation.
*/
NotificationHubService.prototype.createRegistrationId = function (callback) {
  validateCallback(callback);
  var webResource = WebResource.post(this.hubName + '/registrationids');
  webResource.headers = {
    'content-length': null,
    'content-type': null
  };
  this._executeRequest(webResource, null, null, null, function (err, rsp) {
    var registrationId = null;
    if (!err) {
      var parsedLocationParts = url.parse(rsp.headers.location).pathname.split('/');
      registrationId = parsedLocationParts[parsedLocationParts.length - 1];
    }
    callback(err, registrationId, rsp);
  });
};
Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Thanks Jason Pan. I am using var azure = require('azure'); its very old code. Actually, after debugging I am getting an error Error: 10980:error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version:openssl\\ssl\\s23_clnt.c:658 – deepak patil Jan 25 '21 at 07:48
  • @deepakpatil You can try it first. – Jason Pan Jan 25 '21 at 07:49
  • @deepakpatil If my solution inspires or helps you, please mark my answer as [accepted](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) , Tks~ – Jason Pan Jan 25 '21 at 07:49
0

Using the azure-sb node.js module, you should be able to register a device and send to it directly. This requires a connection string and hub, as well as a device token, depending on the platform such as APNS.

import { NotificationHubService } from 'azure-sb';

const CONNECTION_STRING = ''; // Full Access Connection String
const HUB_NAME = ''; // Notification Hub Name
const APNS_TOKEN = ''; //APNS Token

const APNS_MESSAGE = {
  aps: {
    alert: "Notification Hub test notification"
  }
};

service.apns.createNativeRegistration(APNS_REGISTRATION_ID, SAMPLE_TAG, (err, response) => {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Registration success');
  console.log(JSON.stringify(response));

  service.apns.send(SAMPLE_TAG, APNS_MESSAGE, (error, res) => {
    if (error) {
      console.log(error);
      return;
    }

    console.log('Message sent');
    console.log(JSON.stringify(res));
  });
});

When this runs, it should register the device and send to it. I have run this very recently and works without a hitch. The older azure module might be tied to earlier TLS 1.0/1.1, which has since been deprecated for usage on Azure.