cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Getting 404 Error while consuming REST API in BAS SAPUI5 Project

rauf_shaikh
Active Participant
9,223

Hi Experts,

We have a requirement to consume a REST API in an SAPUI5 application developed in SAP Business Application Studio (BAS). I am able to consume ODATA service but for a REST API getting HTTP 404 error code, can you all please look at below scenario and help if I am missing out something. This is now on high priority any sort of help would be much appreciated.

Please note below:

I have create a FIORI app in SAP BAS having Target Runtime as Cloud Foundry and Using MANAGED APPROUTER, app id in manifest is ns.zzidexx2

Create a destination name "jsonplaceholder" in subaccount

Modified xs-app.json to include a route for redirection of API calls to destination

calling the REST API in view controller along with destination name

Tested the destination "jsonplaceholder" from BAS, it is working fine

-Regards,
Rauf Shaikh

Accepted Solutions (0)

Answers (4)

Answers (4)

Hi Rauf,

Facing the same issue. Were you able to resolve it?

0 Likes

Hi Rauf ,

Are you able to solve the issue. I am having the similar requirement

MarcinGajewski
Explorer

Hi Rauf,

Please check following:

1. on your trial account -> go to subaccount -> menu Security on the left side -> Role Collections -> and make sure that at least Business_Application_Studio_Developer is attached to your user. If not - add it and restart BAS

2. go to BAS -> folder .vscode -> open launch.json. Mage sure if your config redirect properly to the destination on this line:

"env": { "run.config": "{\"handlerId\":\"fiori_tools\",\"runnableId\":\"/home/user/projects/project2_rest\"}", "FIORI_TOOLS_BACKEND_CONFIG": "[{\"path\":\"/jsonplaceholder\",\"destination\":\"jsonplaceholder\"}]" }

3. also take a look at Node Debug Console on backend, proxy and destination (should be jsonplaceholder in it)

Debugger attached.
info server:ux-proxy Starting fiori-tools-proxy using following configuration:
info server:ux-proxy proxy: 'http://127.0.0.1:8887'
info server:ux-proxy ignoreCertError: 'false'
info server:ux-proxy backend: [{"path":"/jsonplaceholder","destination":"jsonplaceholder"}]
info server:ux-proxy ui5: {"url":"https://ui5.sap.com","version":"","path":["/resources","/test-resources"],"directLoad":false}
info server:ux-proxy debug: 'false'
info server:ux-proxy Backend proxy started for /jsonplaceholder
info server:ux-proxy Used destination: jsonplaceholder
info server:ux-proxy UI5 proxy started for https://ui5.sap.com
info server:liveload Livereload middleware started for port 35729 and path /home/user/projects/project2_rest/webapp
Server started
URL: http://localhost:8080

4. and when you run the jQuery.ajax in Node Debug Console you will get something like this:

info server:ux-proxy Rewrite path /jsonplaceholder/posts > /destinations/jsonplaceholder/posts

this line is important because there can be route mistake like /destinations/jsonplaceholder/jsonplaceholder/posts

This is the pattern: /destinations/<destination name>/<service path>

adagli
Discoverer

Hi Marcin,

It worked for me. But after deploying to cloud foundry, I can not reach to the URL in the launchpad service.

How can I configure mta.yaml file for backend configuration or destination or routing for my URL from destination service?

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Rauf,

Does the endpoint return successfully in tools like Postman? As mentioned by other users, it doesn't seem to be an issue related to your destination or xs-app.json, so i would suggest cross-checking the API outside of BAS first if you haven't done so yet.

jlong
Product and Topic Expert
Product and Topic Expert
0 Likes

Couple of things;

When running on Business Application studio, ensure the path in the ui5.yaml | ui5-local.yaml is defined as follows;

        backend:
          - path: /jsonplaceholder           
            url: "https://jsonplaceholder.typicode.com/"
            destination: jsonplaceholder

If running on mac or windows, then the URL is read and not the destination since this flow is only supported on BAS.

Also, update your destination configuration properties from odata_abap to odata_json. This is not an ABAP backend which normally exposes catalogs of services.

Please update your curl command to the following, appending the https protocol

curl -v https://jsonplaceholder.dest/jsonplaceholder/posts

If all this works, then the xs-app.json you already have defined should handle the routing when deployed to CF.

John

dibyodeo
Explorer
0 Likes

Hello John ,

I had similar kind of issues. Can you please give me some points where i did wrong .

manifest.json

"Cleartext": { "dataSource": "Cleartext" }xsapp.json { "source": "^/Cleartext/(.*)$", "target": "/$1", "destination": "Cleartext", "authenticationType": "none", "csrfProtection": false },UI5.yml backend: - path: /sap url: https://xyz.com destination: S4HDEV_DEST_S4CLOUD - path: /Cleartext url: "https://api-sandbox.clear.in/einv" destination: CleartextStill it is giving me 404 error .Can you provide some input.BRDD
jlong
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi,

Your destination is configured as a full URL destination i.e. the URL defined should have the full path to the OData XML service. However, if you open a browser tab and hit https://api-sandbox.clear.in/einv this returns 404. So the 404 issue is unrelated to destination configuration, you need to debug why your endpoint is returning this HTTP status.

In your xs-app.json and your ui5.yaml your settings look correct. The issue is with the URL endpoint not exposing a service but instead returning 404.

Refer to Guided Answers for more debugging around full url destinations

https://ga.support.sap.com/dtp/viewer/index.html#/tree/3046/actions/45995:48363:53594:48366:51208

John