on 2021 Jun 18 4:10 AM
Hello Experts,
I'm starting my journey in learning BTP development / JS / TS and SAP Cloud SDK for Javascript.
I'm trying to call API business hub HTTP service that is defined as Destination in the subaccount. It appears like the Destination object is properly retrieved by @sap/destinations lib. But when I attempt to call the API via generated open API library, validation of passed Destination object fails. Could someone give me a hint what is wrong? It appears like SDK validation looks for lowercase object property url, while Destination object includes uppercase URL property. Is this a bug in Javascript SDK?
Regards,
Konstantin
import { Controller, Get } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { any, Destination, DestinationNameAndJwt } from '@sap-cloud-sdk/core';
import { AppService } from './app.service';
import * as xsenv from '@sap/xsenv';
//const xsenv = require('@sap/xsenv');
xsenv.loadEnv();
import * as destinationsClient from '@sap/destinations';
//const destinationsClient = require('@sap/destinations');
import { MaterialApi } from './dmcapi/material';
import { materialDestination } from './materialDestination';
@Controller()
export class AppController {
constructor(private readonly appService: AppService,
private config: ConfigService) { }
@Get('material')
material(): string {
console.log("Executing material() @ Controller");
const destServiceDetails = xsenv.getServices({
destination: { tag: 'destination' }
});
const destClient = destinationsClient(destServiceDetails);
destClient.load("DMC_API_Material").then((materialApiDest) => {
console.log(materialApiDest);
console.log(MaterialApi.findMaterialByPlantAndNameUsingGet1({material: "MAT_1", plant: "UV10", version: "ERP001"}).execute(materialApiDest));
}).catch((err) => {
console.log(err);
})
return "done!";
}
}
Exception:
2021-06-17T22:24:24.46-0400 [APP/PROC/WEB/0] OUT {"message":"The custom headers are provided with the keys: . These keys will overwrite the headers created by the SDK.","level":"warn","custom_fields":{"package":"core","messageContext":"http-client"},"logger":"sap-cloud-sdk-logger","timestamp":"2021-06-18T02:24:24.468Z","msg":"The custom headers are provided with the keys: . These keys will overwrite the headers created by the SDK.","written_ts":1623983064468,"written_at":"2021-06-18T02:24:24.468Z"}
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] OUT Promise { <pending> }
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR (node:151) UnhandledPromiseRejectionWarning: ErrorWithCause: Failed to build HTTP request for destination: failed to load destination!
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at new ErrorWithCause (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/util/dist/error-with-cause.js:32:16)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/http-client/http-client.js:208:15
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at process._tickCallback (internal/process/next_tick.js:68:7)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR Caused by:
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR Error: Property 'url' of destination input must not be undefined.
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at validateDestinationInput (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination.js:60:15)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at Object.sanitizeDestination (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination.js:13:5)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at Object.<anonymous> (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination-accessor.js:76:37)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at step (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination-accessor.js:44:23)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at Object.next (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination-accessor.js:25:53)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination-accessor.js:19:71
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at new Promise (<anonymous>)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at __awaiter (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination-accessor.js:15:12)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at Object.useOrFetchDestination (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/destination/destination-accessor.js:72:12)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR at resolveDestination (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/http-client/http-client.js:207:21)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR (node:151) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
2021-06-17T22:24:24.47-0400 [APP/PROC/WEB/0] ERR (node:151) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The destination object logged by the code and passed to execute() method:
{
owner:
{ SubaccountId: '027eb2....',
InstanceId: null },
destinationConfiguration:
{ Name: 'DMC_API',
Type: 'HTTP',
URL:
'https://dm-prod-prod-fnd-api-gateway-ms.cfapps.eu10.hana.ondemand.com',
Authentication: 'OAuth2ClientCredentials',
ProxyType: 'Internet',
Description: 'SAP DMC Default Destination',
clientId:
'sb-59cc2ebb-544......',
tokenServiceURL:
'https://my-tenant.authentication.eu10.hana.ondemand.com/oauth/token',
clientSecret: 'i5jG....' },
authTokens:
[ { type: 'bearer',
value:
'eyJhbGciOiJ......',
http_header: [Object],
expires_in: '43040',
scope:
'dmc-services!b1334.u dmc-services!b1334.am.i' } ]
}
Request clarification before answering.
Have you tried to simply just call:
sdkDestination = await getDestination(destinationName);
like I do in https://github.com/jowavp/sap-cf-proxy/blob/main/ts/proxy/index.ts#L89. When running locally I need to add:
xsenv.loadEnv();
But I think you can get rid of so much code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like it returns slightly different object than @sap/destinations lib. And now I get another exception in .execute(materialApiDest)
Same as in my response to Junjie Tang
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR [Nest] 152 - 06/18/2021, 2:20:08 PM [ExceptionsHandler] Failed to build HTTP request for destination: failed to build headers! +14029ms
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR ErrorWithCause: Failed to build HTTP request for destination: failed to build headers!
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR at new ErrorWithCause (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/util/dist/error-with-cause.js:32:16)
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/http-client/http-client.js:203:15
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR at process._tickCallback (internal/process/next_tick.js:68:7)
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR Caused by:
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR Error: The destination tried to provide authorization tokens but failed in all cases. This is most likely due to misconfiguration.
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR Original error messages:
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR Could not verify the provided CSRF token because your session was not found.
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR at headerFromTokens (/home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/authorization-header.js:152:15)
2021-06-18T10:20:08.54-0400 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap-cloud-sdk/core/dist/connectivity/scp-cf/authorization-header.js:222:43
User | Count |
---|---|
89 | |
11 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.