Accessing Other Deployments
To access a different deployment within the same app or a different app, a new DB object can be created:
Copy // Same app, different deployment
const otherDB = await CloudCode.createDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/', '{backend-deployment-id}', {username: '{backend-deployment-id}', password: 'mypassword'});
const otherDB = await CloudCode.createDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/', '{backend-deployment-id}', {token: 'mytoken'});
// Example
const otherDB = await CloudCode.createDB('https://62d541f4156bc4dd685318da.backend.us.journeyapps.com/', '62d541ff9f54b7000706c585', {token: 'mytoken'});
// Different app
const otherDB = await CloudCode.createRemoteDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/', '{backend-deployment-id}', {username: '{backend-deployment-id}', password: 'mypassword'});
const otherDB = await CloudCode.createRemoteDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/', '{backend-deployment-id}', {token: 'mytoken'});
// Example
const otherDB = await CloudCode.createRemoteDB('https://62d541f4156bc4dd685318da.backend.us.journeyapps.com/', '62d541ff9f54b7000706c585', {token: 'mytoken'});
Alternative: Accessing APIv4 directly
Copy async function downloadUserData (backend) {
let response = await fetch ( backend .url + '/objects/user.json' , {
headers : {
Authorization : backend .authorization
}
});
if ( ! response .ok) {
throw new Error ( response .statusText);
}
let data = await response .json ();
return data .objects;
}
async function downloadSchema (backend) {
let response = await fetch ( backend .url + '/datamodel.json' , {
headers : {
Authorization : backend .authorization
}
});
if ( ! response .ok) {
throw new Error ( response .statusText);
}
return await response .text ();
}
export async function run () {
let users = await downloadUserData ( this .backend);
console .log ( 'Users' , users);
let schema = await downloadSchema ( this .backend);
console .log ( 'Schema' , schema);
}