Skip to content

Instantly share code, notes, and snippets.

@liflovs
Created December 9, 2020 13:45
Show Gist options
  • Save liflovs/04fb0453a0b37b88228ccf98a5f66510 to your computer and use it in GitHub Desktop.
Save liflovs/04fb0453a0b37b88228ccf98a5f66510 to your computer and use it in GitHub Desktop.
Exchange rate Google App Sript example (EUR to UAH)
function getEuroUahRate(date) {
var str = Utilities.formatDate(date,'GMT+3', 'yyyyMMdd')
var jsonArr = JSON.parse(UrlFetchApp.fetch('https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=' + str + '&json').getContentText())
var json = null
for (var i = 0; i < jsonArr.length; ++i) {
if (jsonArr[i].cc == 'EUR') {
json = jsonArr[i]
}
}
if (json && json.rate) {
return json.rate
} else {
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment