84
Views
8
Comments
Currency conversion by consuming rest api key
Question
Application Type
Reactive

Hi, 

I was given a rest api key 

 https://v6.exchangerate-api.com/v6/19967ef52780f5bf2a77f3aa/latest/USD and I should consume this key in my application and display the currency conversion rate on the screen when he clicks on fetch conversion button. Please see the image.

 After logging in, the user should select the user, upload id proof, select from currency code and to currency code and enter amount, then after clicking on fetch conversion rate button, the currency convertion rate should be displayed.

I had already consumed the rest api but unable to create a logic to display the convertion rate.

please help me


UserImage.jpg
Kay Lun

Hi Gayathri Gali,

I think first you need to know how the conversion works, so your API is using USD as a base conversion, which means, when you selected From AED To BHD, you have to first convert the AED to USD, using the example from your screenshot, 23 AED will convert to 6.26276 USD (23 / 3.6725 at Mon, 29 May 2023 00:00:02 +0000).

After you know how many USD you could get from 23 AED, you just have to use the same table to convert to BHD, which will convert to 2.3548 BHD (6.26276 * 0.3760 at Mon, 29 May 2023 00:00:02 +0000).

So in the end using 23 AED to convert to BHD, should give you 2.3548 BHD.

From the above idea, you should be able to convert them into the logic.

Hope this help :)

Cheers.

KL 

UserImage.jpg
Gayathri Gali
Hi thanks for the reply. We should replace the USD in the URL with the from drop-down value that the user has chosen. I'm not understanding how to use the rest API response in the logic. Can you please tell me clearly?
UserImage.jpg
Kay Lun

Hi Gayathri Gali,

There're different approachs can be used to get what you need. For example, use the data action to fetch the data from the API, and do the logic inside the data action, and display the result with an expression with the output parameter of the data action.

I have uploaded a oml file for your reference, although it only part of the conversion, but I'm sure your will know how to implement the rest of it.

Hope this could give you a better idea.

Thanks,

KL


APIConsume.oml
UserImage.jpg
Gayathri Gali

HI thanks for the reply, 


you have mentioned amount*getLatest.Response.ConvertionRates.BHD.

But What if user selects another currency in the 2nd dropdown. Can you tell me how to retreive the value of a specific currency from the respone?

UserImage.jpg
Gayathri Gali

Everytime the currency in the first dropdown and 2nd dropdown changes so how to get the value of the specific currency dynamically?

UserImage.jpg
Kay Lun

Hi Gayathri Gali,

For getting the correct rate from the API, you need an forge component called ardoJSON to format the conversion_rates into key value pair, so that you could get the correct rate by using the conversion code, I have attached an updated oml for your reference, will leave the rest for you to explore how to correctly bind the dropdown value into the logic, it should be easy.

Hope this give you a better idea on how it actually works.

Cheers :)

KL



APIConsume_updated.oml
UserImage.jpg
Gayathri Gali
Hi
2023-03-16 04-58-56
Ashish Lonkar

Hi Gayathri,

Please take a look at below document, you will be able to figure out solution for your problem from here.

https://medium.com/@jsmarques13/integrating-dynamic-structures-with-outsystems-6c45e36a4d47


Thanks AWL!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.