Skip to content

Instantly share code, notes, and snippets.

@reks-scripts
Created January 2, 2025 20:31
Show Gist options
  • Save reks-scripts/92afcffb8e4e4cd18fbba2cb761a000d to your computer and use it in GitHub Desktop.
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
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