on 01-09-2017 12:52 PM
Hello Experts,
I am trying to invoke Api.ai URL from my UI5 application using AJAX call, code is as follows :
onSearch : function (oEvent) {
var accessToken = "My Access Token";
var messageObject = {};
var that = this;
var baseUrl = "https://api.api.ai/v1/";
var sQuery = oEvent.getSource().getValue();
var sApiResSuccess;
var that=this;
var searchResult = this.getView().byId('productInput1');
$.ajax({
type: "POST",
url: baseUrl + "query",
contentType: "application/json; charset=utf-8",
dataType: "json",
crossDomain: true,
headers: {
"Authorization": "Bearer " + accessToken,
},
data: JSON.stringify({query: sQuery, lang: "en", sessionId: "runbarry"}),
success: function(data) {
sApiResSuccess=data.result.speech;
that._showResult(searchResult,sApiResSuccess);
}
},
error: function() {
respond(messageInternalError);
}
});
},
I have deployed this app on our gateway server and configured the same on our Fiori Launchpad. When I run the standalone BSP application on gateway server , it works fine , I am able to invoke Api.ai ( https://api.api.ai/v1/) , however , when I run the application through launchpad , it gives me CORS Issue , which is - field X-XHR-Logon is not allowed by Access-Control-Allow-Headers in preflight response.
I tried all possible options however not able to resolve this, could you please provide any inputs here ?
Hint : When I installed CORS extension of chrome and enabled it , it worked fine on my launchpad as well however I need to run this app on tablet browser where i can not add any extension.
Any help here would be highly appreciated.
Thanks,
Mahesh Z.
Hello Mahesh,
Jamie's solution will work for you and your scenario (FLP on ABAP gateway). If you want to understand in general why this error occurs you can have a look at the walkthrough tutorial step 26 (scroll down to the middle to find CORS):
https://sapui5.hana.ondemand.com/#docs/guide/44062441f3bd4c67a4f665ae362d1109.html
For the different scenarios (FLP on HCP, FLP on Portal and FLP on ABAP) similar solutions to proxy requests exist.
Regards, Annette
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would want to add the service in gateway so all browser traffic is provided from gateway which would eliminate the error. See
Regards,
Jamie
SAP - Technology RIG
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's a bunch of blogs that you can refer to
I would suggest referring to them and if you have any issues open a new question under the appropriate tag.
Regards,
Jamie
SAP - Technology RIG
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.