Device registration API error 8002

Hello,

I am trying to register a mobile device for Push Notifivation via JS. This is the code:

image

Backendless returns this 8002 error.

Where am I wrong?

Thanks in advance

I’ve tried also in this way:

image

Same error…

Hi, Daniele.
I was able to perform registration on both us/eu clusters without any problems.
Provide your appId to test with.
And it would be nice if you provide the payload in a text form. Also try to do the request in a terminal, e.g. with curl or any other gui app for http requests.

Hello Oleg,

thanks for your reply. Appid is 6F063A9B-BE36-DD67-FF01-2B0EC55C7600

Here the code in txt mode:

requestData = {
“deviceToken”: fbToken,
“deviceId”: “danPhone”,
“os”: “ANDROID”,
“osVersion”: “1.0”
};

$.ajax({
    url: 'https://eu-api.backendless.com/api/messaging/registrations',
    type: 'post',
    data: requestData,
    dataType: 'json',
    async: false,
    success: function (resp) {
        alert(JSON.stringify(resp));
    },
    error: function (err) {
        alert(JSON.stringify(requestData));
        alert(JSON.stringify(err));
    }
});

I’ll try curl as suggested.

Dan

Hi @Daniele_Di_Gregorio ,

Sorry for the long delay with response.
Error, which you encountered, caused by wrong URL which you had used.

When you use general API domain for building routes you should compose URL in next way https://eu-api.backndless.com/{Your App ID}/{Your API Key}/messaging/registrations. In case when you want to use route based on generated or custom domain URL will look in next way https://{generated or custom domain}/api/messaging/registrations.
In example which you have provided you misused /api/ part and used it with general API domain instead of “app ID”/“API key” pair.

Could you please correct this mistake and try again?

Regards, Andriy

Hello Andriy, thanks for your answer. I corrected the code as suggested, but i stumbled into a different error:

  • Json parse error. Wrong json or content type

Shout I pass data into and obj or stringified json? I suppose that this error is caused by an unespected data format passed with the ajax request.

Dan

@Daniele_Di_Gregorio ,

Server API route expects JSON object in request body.

Tried your code in my test app and found that JQuery by default encodes object as sequence of pairs {fieldName}={fieldValue} even when you provide content type “application/json”.

Your request to Backendless API route should look in the next way:

$.ajax({
    url: 'https://eu-api.backndless.com/{Your App ID}/{Your API Key}/messaging/registrations',
    type: 'post',
    data: JSON.stringify(requestData),
    contentType: 'application/json',
    dataType: "json",
    async: false,
    success: function (resp) {
        alert(JSON.stringify(resp));
    },
    error: function (err) {
        alert(JSON.stringify(requestData));
        alert(JSON.stringify(err));
    }
});

Could you please try and confirm that this code worked for you?

Regards, Andriy

Hello Andriy,

done as suggested. Still error:

Here the code:

    requestData = {
        "deviceToken": fbToken,
        "deviceId": "danPhone",
        "os": "ANDROID",
        "osVersion": "1.0"
      };

    $.ajax({
        url: 'https://eu-api.backendless.com/................/............./messaging/registrations',
        type: 'post',
        data: JSON.stringify(requestData),
        dataType: 'application/json',
        async: false,
        success: function (resp) {
            alert(JSON.stringify(resp));
        },
        error: function (err) {
            alert(JSON.stringify(requestData));
            alert(JSON.stringify(err));
        }
    });

Hi @Daniele_Di_Gregorio ,

You didn’t provide contentType value. Instead you put value for content type to dataType. That is why you still receive this exception.

Please put this params to your AJAX request:

  contentType: 'application/json',
  dataType: "json",

Could you please let me know if error has gone?

Regards, Andriy

Opps… sorry, I did not copied tour code properly. Now it’s ok. Succesfully subscribed, thanks a lot :slight_smile:

You are welcome)

I hope you will enjoy further work with Backendless.

Regards, Andriy