Hi Devs,
I went through the ‘Accessing 3rd Party Service’ Documentation and I saw that in your example for getting an exchange rate, you have hard-coded the Base Currency to ‘USD’
This is my Page Code:
import {getCurrency} from 'backend/ArenaApi';
export function button1_click(event, $w) {
getCurrency($w("#currencysymbol").value)
.then(rates => $w("#currencyrate").text = rates);
$w("#currencyrate").show();
}
& This is my Backend:
import {fetch} from 'wix-fetch';
export function getCurrency(currency) {
const url = 'https://api.fixer.io/latest?base=USD'; //base currency hardcoded
let fullUrl = url + '&symbols=' + currency;
return fetch(fullUrl, {method: 'get'})
.then(response => response.json())
.then(json => json.rates[currency].toString());
}
Now here is my question…
I want to be able to send the Base currency from my side too
Can I try something like the below on the Backend:
import {fetch} from 'wix-fetch';
export function getCurrency(currency) {
const url = 'https://api.fixer.io/latest?base=';
let fullUrl = url + (BASE CURRENCY) + '&symbols=' + currency; // base currency
return fetch(fullUrl, {method: 'get'})
.then(response => response.json())
.then(json => json.rates[currency].toString());
}
How should I go about in getting the Base Currency $w(“#basecurrency”).value from the Page ?
Thanks