97
Views
10
Comments
Solved
Exchange rate conversion
Application Type
Traditional Web, Mobile, Reactive, Service

Hi Team,

I have given a api to consume and to develop a currency converter using that.

Can u please guide me how to do that?


2023-05-08 05-34-05
Piyali Saha
Solution

Hi guys,

One way is to list append all the values manually as the response structure has left no other way .

Otherwise the easy way out is to serialize the currency json and use ardoJSON  component to listify the whole json and use the same logic which I have provided in oml.

Here are some forum link yo can refer for further implementation of the above mentioned componenet.

https://www.outsystems.com/forums/discussion/77432/json-structure-into-key-value-pair-ardojson-json-listify/

https://www.outsystems.com/forums/discussion/15179/jsonselect-and-json-getattributes/


2023-05-08 05-34-05
Piyali Saha

Hi Surya,

Could you please share the details or endpoints of api so that I can consume and provide you a demo oml for it?

2023-05-08 05-34-05
Piyali Saha

Hi Surya,

I am defining the pseudo steps to consume an API:

1. Consume single rest API method.

2. Set the method to get and paste the endpoints of the API on the URL

3. Provide headers if any and test the API .

4. After testing copy to response body the response of API as this will create the response structure for your API.

5. Then use can use dataaction to call that method of API and assign the output to display data on the screen.

And if you would provide the API endpoints then I will able to create an exact demo of your scenario.

Also, I am attaching the demo OML of a sample GET API as follows:

ConsumeAPI.oml
UserImage.jpg
Gayathri Gali

Hi, Thanks for the reply,


This is the api key

https://v6.exchangerate-api.com/v6/19967ef52780f5bf2a77f3aa/latest/USD

Please see the above image, if a user selects the From, To, Amount fields and once he clicks on the fetch button, He should get a currency conversion Rate. Here in the api key, we need to replace the USD with the From dropdown value that the user chooses. Please help me with the solution.

2022-08-16 13-41-51
Surya V

Hi Piyali,

Thanks for your response,

My api key :  

https://v6.exchangerate-api.com/v6/19967ef52780f5bf2a77f3aa/latest/USD

So We have to have 2 dropdowns for selecting the currency 

And one input for entering the amount to be converted 

When the user clicks the button then the amount should be converted and we should be able to get the converted amount.

Please help us in this solution of possible please attach the oml file too 


Thanks for the help in advance

2023-05-08 05-34-05
Piyali Saha

Hello guys,

As per the API provided by you, I have implemented the logic to convert currency. 

But I have appended only four values of currency in the list to create a demo.

Hereby, I am attaching the demo oml for you.


CurrencyConvertor.oml
UserImage.jpg
Gayathri Gali

Hi Piyali Saha,


Thanks for the response.

We need to use on before request and on after response in the currency conversion logic. Can you please tell me how to use it?

2023-05-08 05-34-05
Piyali Saha

Hi @Gayathri Gali ,

Here I am attaching the link of use of on before request and on after response. You can customize these methods according to your requirement by referring to the documentation link.
https://success.outsystems.com/documentation/11/extensibility_and_integration/rest/consume_rest_apis/simple_customizations/

If you have any requirement to change header or add new header etc, then you can use on before request method.

I have implemented on after response method in the following oml to write specific message for 200 status code.

CurrencyConvertor.oml
UserImage.jpg
Surya V

Hi Piyali 

got your sample OML file, its working fine for 4 currency codes.

but we need to have more than 75 currency codes and I'm confused to how to do it so hereby i'm attaching the total currency code Excel file. please substitute this list and if possible pls explain me how to do this whole thing.

Country.xlsx
2023-05-08 05-34-05
Piyali Saha
Solution

Hi guys,

One way is to list append all the values manually as the response structure has left no other way .

Otherwise the easy way out is to serialize the currency json and use ardoJSON  component to listify the whole json and use the same logic which I have provided in oml.

Here are some forum link yo can refer for further implementation of the above mentioned componenet.

https://www.outsystems.com/forums/discussion/77432/json-structure-into-key-value-pair-ardojson-json-listify/

https://www.outsystems.com/forums/discussion/15179/jsonselect-and-json-getattributes/


UserImage.jpg
Kay Lun

Hi Surya V,

Using the api url to setup the consume function, simply use the single method API, copy and paste the api url beside the get field, hit the test button in test tab, after the api called is success, press the copy to response body button, and hit finish.

In this way, OS will help you to setup the consume function automatically, after the setup is finish, you could simply use the API action based on different usage and scenario.

for conversion, I guess you could do the calculation in screen action, and return the result back to the screen.

Hope this could give you a better idea on how API works in OS.

Cheers :)

KL

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