Reputation: 21
I want to use the authentication stored in the SAP BTP destinations for a jquery ajax request in my sapui5 controller.
I tried a few different approaches I found searching for this problem, but none worked.
Currently I have the destination configured in the xs-app.json, ui5.yaml and as a dataSource in manifest.json.
JQuery.ajax({ url: "/destinationname/apipath.../", method: "POST",...})
When I deploy the app the request returns 403 Forbidden.
In the BAS terminal I can use the destination with curl "/destinationname/apipath.../"
Following https://stackoverflow.com/a/77346974/23212005 the provided code doesn't work for me, as it only returns the app id specified in manifest.json sap.app. But copying the id from the deployed app in the format of "uuid.appname-0.0.1" the destination is used in the jquery.ajax call. Is there a way to dynamically get this id format?
I'm not a fan of this solution, but it works fine so far:
var path = window.location.pathname;
var endIndex = path.indexOf("/", 1);
appId = path.substring(0, endIndex !== -1 ? endIndex : undefined);
url =
appId + "/<destination>/<apipath>"
Upvotes: 2
Views: 675