Connection to a Full Sync Realm returns 400 Bad Request

Hello there,

I’m trying to develop a simple script that connects to my Realm Object Server instance in Realm Cloud, but I keep getting the error:

ERROR: Connection[1]: Websocket: Expected HTTP response 101 Switching Protocols, but received:
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 14
Content-Type: application/json; charset=utf-8
Date: Wed, 05 Feb 2020 14:41:55 GMT
ETag: W/"e-G3695v1YRbW4oX5T4IAWdmV3xMI"
X-Powered-By: Express

{"status":400}
Connection[1]: Connection closed due to error
{ message: 'Operation canceled', errorCode: 1 }

The authentication is performed successfully, and the Realm is created (I checked in Realm Studio), but when it comes to open the Realm, this error is returned.

Here is my code:

const Realm = require('realm');
const schema = [
  {
    name: 'Car',
    properties: {
      make:  'string',
      model: 'string',
      miles: {type: 'int', default: 0},
    }
  },
  {
    name: 'Person',
    properties: {
      name:     'string',
      birthday: 'date',
      cars:     'Car[]', // list of cars
      picture:  'data?'  // optional property
    }
  },
];

const main = async () => {
  const config = {
    url: 'https://myurl.us1.cloud.realm.io',
    realm: 'realms://myurl.us1a.cloud.realm.io/~/privateRealm',
    file: 'realm/development.realm',
  };

  const createUser = true;
  const username = 'test-user';
  const password = 'test-password';
  const fullSynchronization = true;

  const credentials = Realm.Sync.Credentials.usernamePassword(
    username, password, createUser,
  );

  console.log({
    createUser, username, password,
  });

  try {
    const user = await Realm.Sync.User.login(config.url, credentials);
    console.log(`User ${username} logged in successfully!`);

    const realmConfig = user.createConfiguration({
      schema,
      sync: {
        url: config.realm,
        fullSynchronization,
      },
      path: config.path,
    });

    const realm = await Realm.open(realmConfig);

    console.log(`Connected to Realm successfully!`);
  } catch (e) {
    console.log(e);
  }

  process.exit();
};

main();

Thanks for the help!

I realized that I was authenticating in another server (domain us1a.cloud.realm.io), while the correct was to use us1.cloud.realm.io. But thanks anyway!