JS API - CORS header 'Access-Control-Allow-Origin' missing

Following the example for the real time database:

My code is as follows

const API_HOST = 'https://api.backendless.com';
const APP_ID = '***';
const API_KEY = '***';

Backendless.serverURL = API_HOST;
Backendless.initApp(APP_ID, API_KEY);

const MoviesTable = Backendless.Data.of('Movies');
MoviesTable.find(Backendless.DataQueryBuilder.create().setPageSize(100).setSortBy('created')).then(result => { console.log(result); });

I am running the example on localhost.
I receive the following error log.

GET: https://api.backendless.com/***/***/data/Movies?pageSize=100&sortBy=created
[HTTP/1.1 401 Unauthorized 222ms]

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at 
https://api.backendless.com/***/***/data/Movies?pageSize=100&sortBy=created. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Uncaught (in promise) Error: Network Error
    onerror https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    v https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    v https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    send https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    value https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    value https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    e https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    u https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    _invoke https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    t https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    n https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    a https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    exports https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    exports https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    value https://api.backendless.com/sdk/js/latest/backendless.min.js:15
    <anonymous> http://localhost:8080/script.js:19

I have set the permissions for the table to enable GET requests for the JS API. I am using the JS API key. I have found no other similar forum posts.

Hi James,

Please make sure to substitute app id and API key with the values from your app here:

const APP_ID = ‘’;
const API_KEY = '
’;

Regards,
Mark

Don’t worry about that, I was just self-censoring.

My issue was much simpler.

Use the european URL if your project is on an EU server.

Replace const API_HOST = 'https://api.backendless.com';

with const API_HOST = 'https://eu-api.backendless.com';

Maybe update the tutorial to include this? It was mentioned in the getting started tutorial, but I forgot about it until now.

Thanks for reporting this issue, we are adding additional information to the guide soon.

1 Like

Hi James,

The article has been updated on our site. Thank you for bringing this to our attention.

Regards,
Mark