JS API Backendless.Messaging.registerDevice throws "Class not found"

Hello,

I’m developing and app with ionic but I’ve been looking for a while for an example using the JS API for registering the devices for push notifications (already followed the steps in the docs API keys, got the device ID and all that) I have no problems with adding users into backendless but the registerDevice method fails when calling this line in backendless.js

“window.cordova.exec(success, fail, “PushNotification”, “registerDevice”, [config]);”

and in the fail function there just gives me this log

““Class not found”, source: file:///android_asset/www/lib/backendless/backendless.js (3293)”

so I have no idea what is going wrong here, I would appreciate any help

Thanks

Registering device requires native code. I know ionic recommends a plugin that handles it, so there is a chance it would work. Generally speaking, it works like this:

On Android:
Application manifest must include BackendlessPushService and BackendlessBroadcastReceiver (see the doc at: https://backendless.com/documentation/messaging/android/messaging_push_notification_setup_androi.htm). These classes handle registration of the device with GCM and also perform registration of the device with Backendless. How do it from JS, I do not know, but all the code on the client side we publish is open source and you’re welcome to look into it.

On iOS:
The first step is to obtain a token from APNS. It is also must be done with native code. iOS provides native API to do it. How to call that API from JS, I do not know. Once the token is obtained, it must be sent to Backendless. It can be done with the following REST call:
https://backendless.com/documentation/messaging/rest/messaging_device_registration.htm

Regards,
Mark

Hello Mark,

I moved to the REST option, however I’m getting

“Internal server error with id 500B7E3B-F90E-7247-FF74-79785382E100”

Do you have any idea what could be happening here?

Thanks

Do you get the error in response for this api call?:

https://backendless.com/documentation/messaging/rest/messaging_device_registration.htm

Yup

I think the problem was js was taking away the quotations from some strings, now im getting a 502 Bad Gateway

Still getting 500/502 errors when trying to register the device :confused:

What does the request look like? What do you have for the URL, headers and the body?

Ofc the “xxxx” values have a real value

var devData = ‘{“deviceToken”: null,“deviceId”: “xxxxxxxxx”,“os”: “ANDROID”,“osVersion”: “5.1 .1”,“channels”: [“default”],“expiration”: “2035-05-01T05:03:32+00:00”}’;
var stri = JSON.parse(JSON.stringify(devData));

var req = new XMLHttpRequest();
req.onreadystatechange = function(){
console.log("((((((((((((REQUEST)))))))))) “+req.status);
console.log(”((((((((((((REQUEST STATUS)))))))))) "+req.statusText);
}
req.open(“POST”,“https://api.backendless.com/v1/messaging/registrations”);
req.setRequestHeader(‘application-id’, “xxxxxxxxxxxxxxxxxx”);
req.setRequestHeader(‘secret-key’, “xxxxxxxxxxxxxx”);
req.setRequestHeader(‘application-type’, “REST”);
req.setRequestHeader(“Content-Type”,“application/json”);

  req.send(stri);

You’re sending null for deviceToken, but it is a required value in that call.

Hey Mark, that was the problem, i thought the device token was the response of the insert, though Im able now to register a device but after I try to send a push notification to it, the device disappears from the devices table, any idea why is this happening?

Also when I try to call the getRegistration REST method it throws me this

code: 5009
message: “Error during subscribing”

with this call:

curl -H application-id:xxxxxxxxxxx -H secret-key:xxxxxxx -H application-type: REST -X GET -v https://api.backendless.com/v1/messaging/registration/xxxxxxx

please provide your application id

thanks Sergey, APP-ID “9FC1F3CD-2980-B64C-FFCF-CA9278DFE400”

For now I moved to the Java/Objective C approaches and got the Android part working now but now I’m having problems with the push notifications on IOS, the device doesn’t get them neither from console / publish method, the device is correctly registered but no notifications on my device

You omitted the mandatory Content-Type header. It should be set to application/json

Sorry, must have omitted it while posting, but that is not the problem since I put it when I make my calls, I get the same error

{“code”:5009,“message”:“Error during subscribing”}