cancel
Showing results for 
Search instead for 
Did you mean: 

How to call AIN APIs from Javascript

former_member229176
Participant

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=appl... -- 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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

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<someID>.hana.ondemand.com/ain/. This is your application url. Use e.g. https://aina<someID>.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.

Former Member
0 Kudos

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.

Answers (1)

Answers (1)

former_member229176
Participant
0 Kudos

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