REST API integration

REST API integration

  
I was trying weather api for my sample test project with open url
  http://api.openweathermap.org/data/2.5/weather?q={London} and added "weather" as output parameter
I got the response but Structure is not getting populated even though i see api name"openweathermap" in Data . Structures,  Should i populate it manually  or will it get populated automatically?  Please help...

I have looked at tickets.json e documentation for consuming REST Api
Solution
Hi Yogesh,

Please try the following:
1. In Service Studo, consume a new REST API;
2. Let the HTTP method as GET;
3. Type the definition of URL of the Weather API: http://api.openweathermap.org/data/2.5/weather?q={City} 
4. Go to a browser and type the URL for London (http://api.openweathermap.org/data/2.5/weather?q=London) and press enter to obtain an example of a response; 
5. Copy the response text and, in Service Studio, paste it in the Response box;
6. Press OK.

This should have created an input parameter called City and output parameter called Response in the REST API method.
And that it! use the actyion in your applications, that it should work fine.

Hope this helps!

Best regards,

jaime

P.S.: I'd like to know which topics you read that did not help you (and if you dont mind, why?). This will surely help us improve the online help.
Solution
Thank you, it works,

Appreciate your help 
Yogesh M wrote:
Thank you, it works,

Appreciate your help 

In our application we integrate most of the features, which is available as REST API.  When I tried to understand through http://www.outsystems.com/learn/training/14/1716/728/retrieve-data-using-rest/#VideoTitle link, its unclear....   

Iam still trying to map response object through sturcture on to table record widgets...
>  I have the response as sturcture.
>  I create a web screen
>  I add a preparation to get data by adding REST > GetWeather Action
>   and in webscreen i add TableRecord Widget
>   I select "Source Record List" as GetWeather.Response.weather (to get array of weather details object)
>   I get table structure by dragging "weather" component from Data>Structure>getweatherResponse > weather.   
As objects array are not records and UI Table record widget expects table Record...   I am not able to get objects into Table record widgets...

Still trying to figure out bringing response of weather into UI table record widgets...

Thanks,
Yogesh.
 
 
Hi Yogesh,

By dragging Weather, you are defining the displayed columns in the Table Records as list elements.


You should drag the Wetaher record definition that is WeatherItem.



It should work this way.

Best regards,

jaime

Thanks for the reply,  

I have couple of things:

1.  "WeatherItem" is available in Sturcture  but it is not available in preparation through "GetWeather" of REST,  I get only "weather".  When i try to map attributes of "WeatherItem" to widgets, it is not available in "Source Record List".   But Attributes of "WeatherItem" and "weather"  are same.
    I am not sure where is "WeatherItem" coming from as response object does not have it.  It is automatically created by outsystems REST functionality.

2.  When i drag "WeatherItem"  into Widget table record, the "Source Record List" is mapping to Widget Record as shown in attached pic weather1.png.   If i manually map to Preparation > GetWeather > weather,   I dont get error but i dont see any data on publishing.  The Weather screen is displayed with "no items to show" message.

3.  I even tried manually mapping each attribute to Preparation >weather > main.  Still no luck.

Not sure what i am missing, going clueless

Thanks,
Yogesh.
Hi Yogesh,

I think the problem here is with attributes that are a list of records.
You have a structure (GetWeatherResponse) with attributes of basic and collection (list) data types.
Basic attributes are direct, but a collection is a list of records, which are defined resorting to another structure.
You can take a look at this topic about data types.

Now, let's se if I can explain it .

GetWeather returns a Response record that is defined by structure GetWeatherResponse. 
You want to list the weather list on screen, i.e., GetWeather.Response.Weather

The Weather attribute is a list (collection) of records, which are defined by the WeatherItem structure.
So, if you want to show the weather list on a Table Records:
1. Set the Source Records List, with the list of records, i.e., GetWeather.Response.Weather
2. In the table records, use the structure (and attributes) that define the records in the list, i.e., WeatherItem 

Does this help?

Jaime
I did exactly as said,  table "Source Record List" is set GetWeather.Response.Weather 
and each table row gets the column from WeatherItem.    I dont get any error but i dont get values, it says "no item to show"
Please see the attached pic for my configuration.   

If i check in postman for the API http://api.openweathermap.org/data/2.5/weather?q={London}.   I see values for weather as "weather": [
    {
      "id": 521,
      "main": "Rain",
      "description": "proximity shower rain",
      "icon": "09d"
    },
    {
      "id": 300,
      "main": "Drizzle",
      "description": "light intensity drizzle",
      "icon": "09d"
    }
  ],

On setting "Source Record List"  immediate next row i see "no items to show".  Why is this message?

Thanks,
Yogesh.
Hi Yogesh,

"No items to show...", is the message that is set in property Empty Message of the List Records you're using.
It means the GetWeather method is returning nothing.
What is the city name you are passing to GetWeather?
I'm sending you an OML in attach with my implementation.
Hope it helps.

Kind regards,

jaime
Jaime Vasconcelos wrote:
Hi Yogesh,

"No items to show...", is the message that is set in property Empty Message of the List Records you're using.
It means the GetWeather method is returning nothing.
What is the city name you are passing to GetWeather?
I'm sending you an OML in attach with my implementation.
Hope it helps.

Kind regards,

jaime
 Hi Jaime,

Your oml file works with data displayed in table record,   I tried changing the "City" parameter to "London" and published the application and when tried in browser, the output data is same as "City".  If i change to any city, the output is alwasys same. It appears we gave some static data to table row...

 Please let me know, what is the difference between sample application that you provided and mine.  

I deleted REST API and reconfigured the same API in sample application and I am back with "no items to show"   :(

2) By consuming the API, do we get dynamic data, if the data changes in the API?  The reason for asking is, we are manually copying RESPONSE to REST Action.

Thanks,
Yogesh.
 
Hi Yogesh,

Can you please send me your OML so that I can analyze it?

Thanks,

jaime
Hi Jaime,

I was trying with contacts application with REST API,  So I have linked phone number in contacts to "Weather" screen.  On clicking phone number Weather screen opens in Browsers. Please find the NewApp.oml file attached for your reference.

Thanks,
Yogesh.
Hi Yogesh,

I've spotted the problem.
You are not passing the "London" value, you are naming the input parameter as London.
You have to pass the "London" value when you use the GetWeather action in the Preparation.
But, you have it empty.



You have two separate things, the declaration of the action and its usage.
In the declaration, the input parameter is City.


 
When you use the GetWeather action in the Preparation, you have to pass which city you want to know the weather, i.e., "London".



And that's it. It should work just fine.

Best regards,

jaime

Hi Jamime,

thanks and it worked,  Do we have these things documented?

Also want to know one more thing...  If we have a response with key value pairs as "{key : ["array1","array2","array3"..]"  is this data type supported?  Can I use list widget to display?

Thanks for all your support,
Yogesh.
Hi,

I think this is the JSON for what you want:
{
"key": [
 {   
     "array": [  
      {"item": "X43",
       "value": 1313},
      {"item": "Z8",
       "value": 81264}
    ]
 },
 {   
     "array": [  
      {"item": "T01",
       "value": 345342},
      {"item": "V22",
       "value": 324}
    ]
 }
  ]
}

It will generate the following structures:

 

Where the response is a Key, i.e., a list (array) of KeyItems.
KeyItem is an Array, i.e., list of ArrayItems.  
You have an array of arrays.

As for displaying them, you have to iterate Key list, and then list  the Array list you want.

Best regards,

jaime
I have something like this 

{"response":["Bagalkot","BangaloreRural","BangaloreUrban","Belagavi","Bellary","Bidar","Bijapur","Chamarajanagar","Chikkaballapur","Chikmagalur","Chitradurga","DakshinaKannada","Davanagere","Dharwad","Gadag","Gulbarga","Hassan","Haveri","Kodagu","Kolar","Koppal","Mandya","Mysore","Raichur","Ramanagaram","Shimoga","Tumkur","Udupi","UttaraKannada","Yadgir"],"statusCode":200,"statusMessage":"Successful"}

Will i be able to use this response with list widget?

-Yogesh
Hi,

Of corse. 
Imagine the REST API method is called GetPlaces.
Execute it in the Preparation.
Then, in the list widget, set the source as GetPlaces.Response.Response
Notice you have Response twice: the first is the output parameter and, the second, the name in the structure (inferred from the name you have in your JSON).
I'd change the JSON definition and replace "response" with "places".
This will give a better reading: GetPlaces.Response.Places

Regards,

jaime
Hi 

I tried populating combo box with response as explained in my previous mail for API
https://aeatlindia.accenture.com/KrishiConnectKAOneAuth/service/districts/Karnataka/ 

I am getting error in "Source Attribute"  It says "Source Record list requires Source Attributes"

I have attached NewApp1.oml file for your reference.

Thanks,
Yogesh.
Hi Yogesh,

When populating a combo box with a list, that list has to have at least an identifier and a value to show.
The combo box displays values to show and when you select one of them the combo box returns the identifier of that selected value.
Check out the video in this link: 
http://www.outsystems.com/learn/training/13/1700/667/use-combo-boxes-to-select-from-a-list/#VideoTitle

Hope it helps.

Kind regards,

jaime
Hi Jaime,

Can you please..  give a sample app (oml file) for populating the response from the API mentioned. 
https://aeatlindia.accenture.com/KrishiConnectKAOneAuth/service/districts/Karnataka/ 

{"response":["Bagalkot","BangaloreRural","BangaloreUrban","Belagavi","Bellary","Bidar","Bijapur","Chamarajanagar","Chikkaballapur","Chikmagalur","Chitradurga","DakshinaKannada","Davanagere","Dharwad","Gadag","Gulbarga","Hassan","Haveri","Kodagu","Kolar","Koppal","Mandya","Mysore","Raichur","Ramanagaram","Shimoga","Tumkur","Udupi","UttaraKannada","Yadgir"],"statusCode":200,"statusMessage":"Successful"}

I tried using list, and combo box but not successful. 

Thanks,
Yogesh.

Hi Yogesh,

The problem here is that you are trying to populate a combo box with a List of Text (the response from the API method).

The combo box only accepts a List of Records. To solve your problem, you need to create a Record (structure or entity) and assign each Text of the answer in a new Record. You will then need to create a List and append those records.

You can check the oml attached to understand better how to solve your problem.

Regards,
António
Thanks for the sample App.

I have used the sample and modified a web page,  where i get response from 
https://aeatlindia.accenture.com/KrishiConnectKAOneAuth/service/districts/Karnataka/ 
populate in compobox and selected item is to get response from other API
https://aeatlindia.accenture.com/KrishiConnectKAOneAuth/service/taluqas?q={district}.

I not getting any error but when i publish and check the output in browser, i get following error

Error:
404 Not Found
 
An internal error occurred and was logged.
Please try again later or contact the administration team.
 
Sorry for any inconvenience.
 
Press here to continue

Not sure where i am missing.

Thanks,
Yogesh.

Hi Yogesh,

The url https://aeatlindia.accenture.com/KrishiConnectKAOneAuth/service/taluqas?q={district} is giving a 404 - not found. You should check if the url is the right one or if there is any problem when connecting to the API.

It will be better for you if you debug the application first instead of asking in the forum and waiting for someone to discover what is bugging (just because you will be stopped too much time). To learn how to debug, check this page http://www.outsystems.com/help/servicestudio/9.0/Debugging_eSpaces/Debug_an_eSpace.htm


I also recommend you to read the documentation about how to consume REST. If you have any question that is not in the documentation please ask.

Regards,
António Pereira
Hi,

If i pass value to request parameter {district} through quotes "BangaloreUrban", it works.  Please help me to get values for request parameter through variable.

If i have a local variable District in Interface, How do i pass value to district variable dynamically?

Thanks,
Yogesh.
Hi Yogesh,

In an action executed from the screen interface, you should assign the value of the local variable to the input parameter of the API method.



Regards,
António Pereira