Skip to Content
1

How to call AIN APIs from Javascript

Mar 30 at 10:12 PM

74

avatar image

Hello Experts,

I have a requirement hwerein I need to call few AIN APIs from a webpage. I have created a webpage where on a click of a button, I want to call AIN API - lets say to get the count of Equipments that I have setup in AIN.

The API URL Provided in the SAP AIN document is:

Application_URL/services/api/v1/equipment/$count

Viewing the Equipment Count

You use this API to get a count of all equipment that you have access for.

Request

  • HTTP Method: GET
  • URL: Application_URL/services/api/v1/equipment/$count?$filter substringof(<FILTER_VALUE>, <PROPERTY_NAME>)
  • Query parameters: $filter

    $filter: allows you to specify a search text using which you can filter the items of equipment

    Description: Where FILTER_VALUE is the parameter to search the text or a substring of the text and <PROPERTY_NAME> is the attribute that contains the text.

  • Example URL: /ain/services/api/v1/equipment/$count?$filter=substringof('Sample equipment',Name)
  • Authorization: You must have the roles EQUIPMENT_READ or EQUIPMENT_EDIT or EQUIPMENT_DELETE assigned to your user IDin the SAP Cloud Platform account.

Lets say my AIN URL is:

 https://abcxyz.dispatcher.hana.ondemand.com/sites?hc_reset#Shell-home

I tried below approaches to form API URL:

https://abcxyz.dispatcher.hana.ondemand.com/services/api/v1/equipment/$count  -- Did not work


https://abcxyz.dispatcher.hana.ondemand.com/sites/services/api/v1/equipment/$count -- Did not work

https://abcxyz.dispatcher.hana.ondemand.com/sites/services/api/v1/equipment/$count?content-type=application/json -- DId not work

For all above URLs,

I am getting Intrnal 500 Error.

  • So what can be the way to form AIN API URL?
  • Also How do I pass basic authentication like username and password in HttpRequest in Javascript?

ANy help would be useful.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Niclas von Caprivi Apr 04 at 03:02 PM
1

Hi Soham,

I had the same problem. I can tell you how I find out the application / API url:
Go to your SAP Cloud Platform. You should find it entering hana.ondemand.com and do some clicking. In your subaccount navigate to Connectivity>Destinations. There should be a destination called ainapp. It provides a link which looks like https://aina . hana.ondemand.com/ain/. This is your application url. Use e.g. https://aina . hana.ondemand.com/ain/services/api/v1/equipment/$count to target the API.

Your credentials (username, password) are part of the request header. I would strongly recommend you to write a UI5 Application inside your Cloud Platform subaccount and use the destination to target the API. Then you don't have to care about the credentials and how to start a ssl encrypted connection.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Just found a better way to find out the application url. In your Cloud Platform navigate to Applications>Subscriptions. You can click on the java application "ain". On the following page you can find the application url.

0
Soham Shah Apr 23 at 11:20 PM
0

Thanks Nicolas. I was able to find the correct URL of the AIN Application.

I wrote UI5 application to call these AIN APIs and deployed them on SAP MII Server. I am able to call these APIs using UI5 app by passing credentials in my AJAX call.

Thanks for the informaiton though.

Soham

Share
10 |10000 characters needed characters left characters exceeded