Hello,
In my multitenant CAP app, I got an error when accessing an S/4HANA Cloud via Cloud SDK from my consumer subaccount. It works fine when accessing from my provider. My scenario is the following:
Perhaps it may seem a little weird the own s/4hana cloud system vs the provider subaccount, it is here just for test purposes.
When accessing https://provider-myapp-aa.cfapps.eu10.hana.ondemand.com/mobile/getData(cardTemplate=''), the own s4hc is reached successfully and data is retrieved but doing so from the consumer, https://consumer-myapp-aa.cfapps.eu10.hana.ondemand.com/mobile/getData(cardTemplate=''), I got the following error in the provider app:
2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT error calling api Error: Could not find a destination with name "s4n103C1"! Unable to execute request. 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at Object.errorWithCause (/home/vcap/app/node_modules/@sap/cloud-sdk-core/node_modules/@sap/cloud-sdk-util/dist/error.js:14:20) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at /home/vcap/app/node_modules/@sap/cloud-sdk-core/dist/request-builder/request-builder-base.js:125:78 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at process._tickCallback (internal/process/next_tick.js:68:7) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT Caused by: 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT Error: FetchTokenError: Client credentials Grant failed! Request failed with status code 401 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at Object.errorWithCause (/home/vcap/app/node_modules/@sap/cloud-sdk-core/node_modules/@sap/cloud-sdk-util/dist/error.js:14:20) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at accessTokenError (/home/vcap/app/node_modules/@sap/cloud-sdk-core/dist/scp-cf/xsuaa-service.js:166:29) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at /home/vcap/app/node_modules/@sap/cloud-sdk-core/dist/scp-cf/xsuaa-service.js:43:57 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at process._tickCallback (internal/process/next_tick.js:68:7) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT Caused by: 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT Error: Request failed with status code 401 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at createError (/home/vcap/app/node_modules/axios/lib/core/createError.js:16:15) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at settle (/home/vcap/app/node_modules/axios/lib/core/settle.js:17:12) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at IncomingMessage.handleStreamEnd (/home/vcap/app/node_modules/axios/lib/adapters/http.js:237:11) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at IncomingMessage.emit (events.js:203:15) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at endReadableNT (_stream_readable.js:1145:12) 2020-04-15T09:46:27.639+0000 [APP/PROC/WEB/0] OUT at process._tickCallback (internal/process/next_tick.js:63:19)
The destination s4n103C1 is created in the provider subaccount and I have made sure that the fields are well filled out. I tried creating the destination in the consumer subaccount and I got the same error.
Let me here remark that accessing other CAP services from the consumer subaccount (i.e https://consumer-myapp-aa.cfapps.eu10.hana.ondemand.com/mobile/books) works fine, the error occurs when accessing backend destinations via Cloud SDK.
The source code that raises the error is:
var cloud_sdk_core_1 = require("@sap/cloud-sdk-core"); const { serializeEntity } = require("@sap/cloud-sdk-core"); // building the select fields array .... var jwt = retrieveJwt(req._.req) // call api const salesOrder = await SalesOrder .requestBuilder() .getAll() .select(...selectFields) .filter(filters) .top(top) .execute({destinationName: destination, jwt: jwt}) .then(result => result.map(so => serializeEntity(so, SalesOrder))) .catch(reason => { console.log('error calling api ', reason) })
This is my mta.yaml file:
_schema-version: 2.0.0 ID: myapp version: 1.0.0 modules: - name: myapp-db type: hdb path: db parameters: memory: 256M disk-quota: 256M requires: - name: myapp-db-hdi-container - name: myapp-srv type: nodejs path: srv parameters: memory: 512M disk-quota: 512M provides: - name: srv_api properties: url: ${default-url} requires: - name: myapp-db-hdi-container - name: myapp-uaa - name: myapp_destination - name: myapp_connectivity properties: SAP_JWT_TRUST_ACL: - clientid: "*" identityzone: "*" DEBUG : "false" - name: myapp-ui type: nodejs path: app parameters: memory: 256M disk-quota: 256M requires: - name: myapp-uaa - name: srv_api group: destinations properties: forwardAuthToken: true strictSSL: true name: srv_api url: ~{url} properties: SAP_JWT_TRUST_ACL: - clientid: "*" identityzone: "*" TENANT_HOST_PATTERN: "^(.*)-myapp-ui.cfapps.eu10.hana.ondemand.com" resources: - name: myapp-db-hdi-container type: com.sap.xs.hdi-container properties: hdi-container-name: ${service-name} - name: myapp-uaa type: org.cloudfoundry.managed-service parameters: service-plan: application service: xsuaa path: ./xs-security.json shared: true config: xsappname: myapp-${space} - name: myapp_destination type: org.cloudfoundry.managed-service parameters: service-plan: lite service: destination - name: myapp_connectivity type: org.cloudfoundry.managed-service parameters: service-plan: lite service: connectivity
Any clues with this issue?
Thanks in advance.
Best regards,
Marc