cancel
Showing results for 
Search instead for 
Did you mean: 

Consuming A multi tenant (capm) api from another multi tenant capm project - destination management

sreehari_vpillai
Active Contributor

Hello.

I have a multi tenancy enabled CAPM project - CRM . This has an app router and a srv application deployed in my dev CF space.

I created another capm project SAAS . I am consuming CRM service from SAAS project following capire. package.json of SAAS application is like this.

"CRMService": { 
"kind": "odata-v4",
 "model": "srv/external/CRMService", 
"[production]": {
       "credentials": { 
              "destination": "CRMSRV", 
               "path": "/crm" 
                      } 
                } 

}

These applications are deployed in BTP Trial sub-account . I created a destination service and a service key , to maintain "CRMSRV" destination ( using OAuth2UserTokenExchange , pointing to srv url of CRM service ) and bound it to SAAS srv application.

From the same Trial account, I created subscription for both CRM & SAAS. Post setting up routes and reroute URL , through saas subscription endpoint , I can reach CRM service - the destination is properly picked up .

Later I created another (consumer) sub-account and subscribed to both CRM and SAAS . CRM url can access the corresponding entity set data and SAAS can access its own. But, when I use SAAS url to fetch CRM data ( since SAAS has CRM api consumption setup ) , I get "Error during request to remote service: Failed to load destination" . sWhat am I missing ?

1 - If I am not creating a destination in consumer sub-account , mustn't it consider the destination of provider sub-account ?

2 - If I must create a destination in consumer sub-account, what would be the target URL ? consumer sub-account URL of CRM ? I tried this and failed.

Is it something missing in the Service.js I implemented ?

Service.js


Error from log

Failed to load destination. Caused by: Could not fetch client credentials token for service of type "destination". Caused by: undefined

Sreehari

sreehari_vpillai
Active Contributor
0 Kudos

jhodel18 gregorw

sreehari_vpillai
Active Contributor
0 Kudos

Update :

a) I changed the authentication from SAAS to CRM to "OAuth2ClientCredentials" . From "trial" sub-account I can still access the CRM service via SAAS.

b ) I added destination option in the package.json of SAAS to enforce system to consider the destination of provider's sub-account. Getting this error , when accessing the URL of "trial" subscription.

'Failed to load destination. Caused by: this.options.selectionStrategy is not a function'

"destinationOptions": {
              "selectionStrategy": "alwaysProvider"
            }

is there any blogs or documents explaining how 2 multi tenant micro services interact each other ?

sreehari_vpillai
Active Contributor
0 Kudos

^^ error in scenario a) is

'Failed to load destination. Caused by: Could not fetch client credentials token for service of type "destination". Caused by: undefined' -

Accepted Solutions (0)

Answers (3)

Answers (3)

sreehari_vpillai
Active Contributor

Update :
following this issue raised by Gregor here . for me, request.attr.token is undefined . But , retrieveJwt function from sap-cloud-skd retrieves it - Console says request.attr is deprecated . I don't see an option in

service.tx(request).run(request.query); 
to propagate the jwt explicitely .
gregorw
Active Contributor

Does you MTX app return the dependency for the destination service as I've described in Documentation: Deploy SaaS Solutions (MTX) - Dependencies to Destination / Connectivity Service?

sreehari_vpillai
Active Contributor
0 Kudos

Yes I have tried that.

uaa.user scope was missing in my xs-security.json , added that as well and tried. Stands at the same place - Provider account's own subscription works fine. When consumed from another sub-acccount , the call fails with error

Failed to load destination. Caused by: Could not fetch client credentials token for service of type "destination". Caused by: undefined'.

I am using "OAuth2UserTokenExchange" as authentication type. Also tried with OAuth2ClientCredential. Must I be using something else ? I am trying to make one scenario work .


>> I used "Common" token service url with {tenant} placeholder. This behaves the same as well. I tried to fetch the token from postman , using OAuth credential ( using tenant.authentication...ondemand.com/oauth/token , and it works fine there )

Sreehari

Attila
Active Participant
0 Kudos

Hi sreehari.vpillai ,

did You overcome this issue maybe and somehow :). It would be great if You could serve with some good news. At least to get some hope here 🙂 !

I also added connectivity to mta.yaml, and bound it to the application.

Besides I added the code suggested by Gregor here and also added connectivity to getDependencies handler, but unable to get the destination, even doing a new subscription again.


It still runs to issue

TypeError: this.options.selectionStrategy is not a function  
at DestinationFromServiceRetriever.getSubscriberDestinationService <br>

Thank You

Best regards

Attila

Update 16.Match.2023

I was told a "magic trick" to overcome the issue, since increasing the CAP versions in package.json did not help. In case You need the subscriber destination fetched first in node.js, then better completely ignore the "alwaysSubscriber" part, due it is the default. After removing it, the above exception in CAP runtime disappeared.

sreehari_vpillai
Active Contributor

been there , faced all these myself. I gave up ( its a shame to say that ) after numerous failed attempts.
But , I will be there soon - I am retrying it . If it still fails, I will raise a support incident ( yes , I'm SAP customer now ) and get SAP expert's help on this.

keep you posted.

Sreehari

monokizsolt7
Participant
0 Kudos

I had to increase @sap-cloud-sdk/http-client version to 3.1.1 and call it like this:

const { data } = await executeHttpRequest( {

destinationName: "my-dest",

jwt: retrieveJwt(req),

selectionStrategy: DestinationSelectionStrategies.alwaysSubscriber, },

...