on 11-23-2022 10:44 AM
Hi,
We all know that using Northwind OData on BAS and/or Launchpad services for HTML5 apps works perfectly fine. However when we use REST API and try to follow same steps we run into issues when running HTML5 app from sites on Launchpad services. Surprisingly, app run from BAS works fine.
I have gone through blog series SAP Tech Bytes: Consume Data Using Destinations with an Approuter – Cloud Foundry Basics #3 by nicolai.geburek however have no luck yet.
Sharing some details and github repo as well
Github Repo to review xs-app.json, ui5.yaml etc
BTP destination config:
Issue:
Ajax code:
Error for Ajax call under network tag
When we look at other calls on Network tab, I see one of them trying to call $metadata and when I use the Reuest URL and manually change the path I am able to reach the destination. However this doesn't happen when a AJAX call is made from one of the controllers :
manually change the path
In other words, I understand is that, Launchpad service could use destination service(shown below) for OData calls however fails to do the same when a ajax call is made from app
Hi kevindass,
It is a good sign that you can manually call the /api/users?page=2 endpoint. I believe there is only one thing you have to change in your ajax call to make it work as well. You need to get the complete path of your Launchpad application and append api/users?page=2 to that, instead of just calling the endpoint as a relative path. I did something similar here.
The reason for the (failing) metadata call in your application is that you defined a data source and OData model in your manifest.json file (here). The api you are consuming is not OData, so define a JSON model instead. You specified "JSON" as the type in the data source, so you can skip all other settings in the model definition to achieve that (see an example here). In fact, the way you are currently manually calling your api via an ajax call, you wouldn't need a model at all, although it is better to use one.
Hope this helps. Let me know in case you have more questions.
Best, Nico
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nicolai.geburek thank you for you reply.
I did follow your pointers, however it didn't help to resolve. Below are results.
This is what I see:
Network tab:
My observations:
URL from site when app is loaded:
What we actually need:
Request URL:
https://XYZ.launchpad.cfapps.ap21.hana.ondemand.com/e8903e10-444c-4956-91b8-b99a2c18c88b.reqres.reqr...
Regards,
Kevin Dass
nicolai.geburek to answer, “How did I get URL” is by looking at failed metadata call in network tab and manually framing it. I understand now your solution but this would be a common approach, so could you share any existing blogs so that I know how to programmatically arrive at destination service instance in controller and place it during ajax call?
I understand I have to programmatically lookup below destination service instance. But how could I do so?
Hi kevindass,
Interesting, I didn't notice the working URL was composed of the instance ID of your destination instance. I don't believe this is how you are supposed to call the destination service.
What happens when you call https://XYZ.launchpad.cfapps.ap21.hana.ondemand.com/api ?
Hi kevindass,
I submitted a pull request in your repo that fixes the issue. The ajax request now includes the application id when not running locally (e.g. in the Fiori Launchpad). The rest of the project (xs-app.json, destination, managed approuter) was set-up fine 👍
Best, Nico
Marking this as answered and solution is provided on Github Repo.
Do check comments under "Pull Request" tab for more information
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.