Created
January 2, 2025 20:31
-
-
Save reks-scripts/92afcffb8e4e4cd18fbba2cb761a000d to your computer and use it in GitHub Desktop.
Google Sheets Apps Script function to get the current price of Gold from goldapi.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getGoldPrice() { | |
const accessToken = 'goldapi-XXXXXXXXXXXXXXX-io'; | |
const headers = { | |
'x-access-token': accessToken, | |
'Content-Type': 'application/json' | |
}; | |
const options = { | |
'method' : 'get', | |
'headers': headers, | |
'muteHttpExceptions': true | |
}; | |
const response = UrlFetchApp.fetch("https://www.goldapi.io/api/XAU/USD", options); | |
const json = JSON.parse(response.getContentText()); | |
const price = json.price || "Price not found"; | |
Logger.log("Current Gold Price: " + price); | |
return price; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment