cancel
Showing results for 
Search instead for 
Did you mean: 

SAP BTP Launchpad Services- Integrate the REST API via Destination Service for Fiori app

kevindass
Participant
0 Kudos

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

REST API endpoint

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

Accepted Solutions (1)

Accepted Solutions (1)

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

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

kevindass
Participant
0 Kudos

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:

https://XYZ.launchpad.cfapps.ap21.hana.ondemand.com/site?siteId=2c369f17-05af-4276-a234-c85e93df2996...

What we actually need:

Request URL: https://XYZ.launchpad.cfapps.ap21.hana.ondemand.com/e8903e10-444c-4956-91b8-b99a2c18c88b.reqres.reqr...

Regards,

Kevin Dass

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

Hi Kevin,

how did you find the request URL that is working? You basically have to get e8903e10-444c-4956-91b8-b99a2c18c88b.reqres.reqres/~281122115118+0000~ dynamically (programmatically) and include it in your ajax request.

Best, Nico

kevindass
Participant
0 Kudos

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?

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

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 ?

kevindass
Participant
0 Kudos

nicolai.geburek this is waht I see in network tab when app runs from launchpad

However from BAS destination is reachable and connects to REST api

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

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

kdass_lb
Explorer
0 Kudos

nicolai.geburek Much appreciated. Post I implement your changes I still do not see a success.Is this anything to do with trail account setup v/s your account setup?

Could you let me know what path you get in variable "myPathWithoutFile" ?

kevindass
Participant
0 Kudos

Marking this as answered and solution is provided on Github Repo.

Do check comments under "Pull Request" tab for more information

Answers (0)