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

SAP Analytics Cloud Custom Widget Calls a SAP CPI REST API - Failed with CORS Error

cp11
Explorer
0 Likes
1,138

Hello experts,

I am currently trying to make a call to the SAP CPI I-Flow via an SAP Analytics Cloud Custom Widget.

The I-Flow is triggered via REST-API and everything works so far via Postman with Basic Authentication via ClientID + ClientSecret.

Unfortunately, the REST-API call fails when I try it from the SAP Analytics Cloud/Javascript.

Here you can see my current I-Flow Settings in the REST-API: 

cp11_1-1719908220976.png

 

Here you can see my current coding in SAP Analytics Cloud/Javascript:

AJAX Call: 

$.ajax({
  url: apiUrl,
  type: "POST",
  headers: {
    "Authorization": "Basic " + btoa(username) + ":" + btoa(password)
  }
})
  .done(function (data){
  $.each(data, function (key, value){

  })
})
  .fail(function (jqXHR, textStatus){
  alert("Error: " + textStatus);
})


I get the following error when executing:

cp11_0-1719907862427.png

it has something to do with Cors Policy, but i dont know exactly how to handle this problem. 

I also tested it with the Fetch Call but the same error appears. 

Can you help me here what my error could be?

If you have any further questions, please do not hesitate to contact me.

Best regards

Chris.

 

Accepted Solutions (1)

Accepted Solutions (1)

MAVR
Product and Topic Expert
Product and Topic Expert

Hi Chris,
This is the expected behavior, and the reason is that SAP Cloud Integration does not reply correctly to the HTTP OPTIONS call. You must use API Management before your SAP Cloud Integration endpoint to avoid CORS issues. 

Please find the tutorial as part of the SAP Learning" https://developers.sap.com/tutorials/btp-integration-suite-integral-api-management.html

The important thing is that your policy sets the correct response to every CORS request.

MAVR_0-1719989998104.png

I hope this helps you.

Best regards 🖖🏻

 

cp11
Explorer
0 Likes

Hi Mavr,

this was exactly the solution i was searching for 🙂 

Thank you very much for your Help

Best Regards 

Chris P. 

Answers (0)