cancel
Showing results for 
Search instead for 
Did you mean: 

Consumption of an API within a Custom POD Plugin in SAP DMC

angelbryan
Explorer
886

Hello experts!

Following the topic read at https://community.sap.com/t5/technology-q-a/sapui5-app-on-cf-gt-xs-app-json-route-destination-in-btp..., development was carried out to consume an API to display order characteristics in a table in a custom Order POD.

The resource spfioriapp-dest-srv was configured in the mta.yaml.

imagen.png

The destination was created in the spfioriapp-dest-srv service.

imagen (1).png

The destination was added to the xs-app.json.

imagen (2).png

Example of the AJAX method of type GET in the controller with the URL towards the defined destination.

imagen (3).png

The MTA is compiled and deployed. And finally, in the generated link of the application when deployed, the data is correctly retrieved.

imagen (4).png

However, when executed in the Order POD, the call is made from the DM Host and shows a "Not Found".

imagen (5).png

What is missing or what would be the path for the correct operation of the API within the execution of the Order POD?

Thank you very much in advance.

Best regards.

 

View Entire Topic
tobias_renth
Participant

It is not possible to make API calls from the plugin with a relative path, as it will use the path of SAP DM, where this destination cannot be found.

For DM own APIs, I would suggest to look into the getPublicApiRestDataSourceUri function from the ProductionComponent.

If you want to call other APIs, there are two possibilites:

You could register them in DM and use them in a production process. Call the production process from the plugin using getPeRestDataSourceUri function.

Or directly call it from the plugin using a BTP destination and the application router. In this case, you cannot use a relative path. The path needs to begin with the absolute path of your plugin application URL, followed by the term from the app router (in your case /sapApi). So something like https://<appURL>/sapApi/order/...

angelbryan
Explorer

Hello tobias. Thank you for your answer.

 

We already tried the absolute route: https://<appURL>/sapApi/order/ but we face CORS issues doing it that way.

 

What can we do to solve it?

tobias_renth
Participant
Add the route from the app router (sapApi in your case) to the CORS section in the mta.yaml file
javierrubio_01
Explorer
0 Kudos
Hi Tobias, sorry can I ask please where can I find the code for the function getPublicApiRestDataSourceUri?. I can see this function being called in the sap examples but cannot see its logic? : https://github.com/search?q=repo%3ASAP-samples%2Fdigital-manufacturing-extension-samples%20getPublic...
tobias_renth
Participant
0 Kudos
getPublicApiRestDataSourceUri is a function from the plugin framework. I am not sure if it is possible to look at the source code, but it is referenced in the documentation. Either directly here: https://github.com/SAP-samples/digital-manufacturing-extension-samples/blob/main/documentation/jsdoc... or you could download the JS Docs from GitHub and check it locally
javierrubio_01
Explorer
0 Kudos
Thanks for your quick response but I am still struggling to understand: do I need to call that function in my custom plugin as it is already available in the framework?. No parameters have to be passed?
tobias_renth
Participant
0 Kudos
In the plugin controller you can create an URL like this example for the get work center public API: var url = this.getPublicApiRestDataSourceUri() + "workcenter/v1/workcenters?plant=" + plant + "&workCenter=" + workCenter; Then you can use this.ajaxGetRequest wo make the API call for this URL
javierrubio_01
Explorer
0 Kudos
thanks again Tobias but if I use your approach I have the error 'getPublicApiRestDataSourceUri() is not a function'