cancel
Showing results for 
Search instead for 
Did you mean: 

CAP: run cql queries in custom endpoints

0 Kudos

Hi everyone,

I have a problem with run cql queries in custom endpoints in a muntitenant scenario, I followed the next example for create a custom endpoints to response in json format, works fine in an single tenant scenario, but when I tried take it a multitenant I got the next error:

There is no instance for tenant "anonymous"

I tried with the instructions cds.run() and tx.run() but none worked for me.

I would appreciate if someone could help me

Accepted Solutions (1)

Accepted Solutions (1)

vitaly_kozyura
Participant
0 Kudos

Hi Johan,

The tenant information is stored in the req object: https://cap.cloud.sap/docs/node.js/events#cds-request. You should provide this information to your transaction: https://cap.cloud.sap/docs/node.js/transactions. Something like

const tx = cds.tx(req)

OR

const tx = cds.tx({ user: new cds.User({ id: 'user', tenant }) })

AND THEN

const rs = await tx.run('...')

Best regards,
Vitaly

0 Kudos

Hi Vitaly,

actually I tried to do the following:

let db = await cds.connect.to('db');
const tx = db.tx();

and the following also:

const tx = cds.tx(req);

but what really worked for me was the following:

const tx = cds.tx({

user: req.authInfo.getEmail(), 

tenant: req.authInfo.getSubaccountId()

});

I don't know the reason why the above statements didn't work, I'm very grateful to you Vitaly

Answers (0)