Home > Forum > Rules, JS, SQL > [SOLVED] Call REST API from Item List Row

[SOLVED] Call REST API from Item List Row
0

MVP

Hey everyone,

I have the following challenge. I'm storing travel expenses in an item list. The expenses could be in various currencies. I'd like to get the exchange rate automatically for each row (because the exchange rate might be different for different dates and currencies).

The API GET call is: https://kurs.resenje.org/api/v1/currencies/<CODE>/rates/<YEAR>-<MONTH>-<DAY>

I have <CODE> in DET_Att6 and the <DATE> in DET_Att3.

The response is a JSON:

{
"code": "USD",
"date": "2017-01-04",
"date_from": "2017-01-04",
"number": 1,
"parity": 1,
"cash_buy": 117.7702,
"cash_sell": 119.4306,
"exchange_buy": 118.2446,
"exchange_middle": 118.6004,
"exchange_sell": 118.9562
}

What I wanted to do was:
- make the user insert all the information in the row;
- after that the user has to click the button in the row that would make the API call and save the "exchange_middle" in a column (e.g. DET_Att5)

Does anyone has any ideas how to implement that? Or, any ideas to do it differently?

Any tips will be much appreciated!

Cheers,
Martin

MVP

Hi
Perhaps it would be sufficient to set the rest data source to the default value of the item list attribute?

This will work only after saving the form, I have no idea how else to trigger the refresh of the default value in the list.
You can clear the result after changing the date, currency and after saving again will set for the new values.

Regards


--Edit
late hour and my thinking retarded :)
After all, you can add a business rule with this source in the form rule for changing the value in code or date. Then you don't need the default value.