Skip to content

Instantly share code, notes, and snippets.

@tofikhidayatxyz
Created June 14, 2023 16:44
Show Gist options
  • Select an option

  • Save tofikhidayatxyz/e19163c80faca8680fe0a4e5bef6aa57 to your computer and use it in GitHub Desktop.

Select an option

Save tofikhidayatxyz/e19163c80faca8680fe0a4e5bef6aa57 to your computer and use it in GitHub Desktop.
Get wise currency using google script
function getWiseAPI(fromCurrency='EUR', toCurrency='IDR', price=1) {
if(typeof fromCurrency != 'string') {
fromCurrency = 'EUR'
}
if(typeof toCurrency != 'string') {
toCurrency = 'EUR'
}
if(typeof price != 'number') {
price=1
}
try {
const url = `https://api.wise.com/v1/rates?source=${fromCurrency}&target=${toCurrency}`;
const headers = {
"Authorization": "Basic OGNhN2FlMjUtOTNjNS00MmFlLThhYjQtMzlkZTFlOTQzZDEwOjliN2UzNmZkLWRjYjgtNDEwZS1hYzc3LTQ5NGRmYmEyZGJjZA=="
};
const options = {
method: "get",
contentType: "application/json",
muteHttpExceptions: true,
headers: headers,
};
const response = UrlFetchApp.fetch(url, options);
const json = JSON.parse(response.getContentText());
const rate = parseFloat(json[0].rate)
const total = parseFloat((price * rate).toFixed(3))
console.log(total)
return total
} catch (e) {
Logger.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment