Exchange Rate API Return Data

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
customaware
Posts: 2391
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Exchange Rate API Return Data

Post by customaware »

I am trying a new Exchange Rate API Service.

It returns data in this format.....

Code: Select all

{
	"meta":{
		"last_updated_at":"2023-04-22T23:59:59Z"
		},
	"data":{
		"AED":{
			"code":"AED","value":4.075241
			},
		"CAD":{
			"code":"CAD","value":1.517868},
		"USD":{
			"code":"USD","value":1.109754}
		}
}
I guess there are two ways to possibly process this...
Option A: Construct the correct BO Return Structure. But it seems to me that have each pair Prefixed by the Currency Code means that won't work.
Option B: Read all in as a String (I can get that bit working) and then use the PARSE_JSON function to extract the data.

For Option B I already have a BO with Code and Value Pairs.
Currency
Code PLAIN TEXT
Value NUMBER

But I cannot work out how to structure the PARSE_JSON function properly.

Any ideas / clues or solutions here would be greatly appreciated.
Cheers,
Mark
_________________
AwareIM 6.0, 8.7, 8.8, 9.0 , MariaDB, Windows 10, Ubuntu Linux. Theme: Default, Browser: Arc
Upcloud, Obsidian....
Image
customaware
Posts: 2391
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: Exchange Rate API Return Data

Post by customaware »

Worked it out....

Currency.Value=PARSE_JSON(RESTCurrencyResponse.Reply,'$.data.' + Currency.Currency + '.value')

Where Currency.Currency is the Currency Code... ie USD
Cheers,
Mark
_________________
AwareIM 6.0, 8.7, 8.8, 9.0 , MariaDB, Windows 10, Ubuntu Linux. Theme: Default, Browser: Arc
Upcloud, Obsidian....
Image
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Exchange Rate API Return Data

Post by PointsWell »

Out of interest what API are you using?
customaware
Posts: 2391
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: Exchange Rate API Return Data

Post by customaware »

I have used Mondor for years. Started right back in http SOAP days...

Thought it time to upgrade....

Currency API provides a Free plan for up to 300 calls per month. I have less than 10 Currencies can do a call every night
and still be under the Free threshold.

https://currencyapi.com/
Cheers,
Mark
_________________
AwareIM 6.0, 8.7, 8.8, 9.0 , MariaDB, Windows 10, Ubuntu Linux. Theme: Default, Browser: Arc
Upcloud, Obsidian....
Image
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: Exchange Rate API Return Data

Post by PointsWell »

Cool. I looked at that for a minute a while ago will check it out again
Post Reply