Live Exchange Rates in Google Sheets and Excel via API (No Add-ons)
Pull live exchange rates in Google Sheets with Apps Script and in Excel with Power Query: custom functions, caching, scheduled refresh and a private API key.

- In Google Sheets, a short Apps Script with `UrlFetchApp` and `CacheService` adds a `=EZRATE("usd")` function.
- In Excel, Power Query reads the JSON endpoint with a header and refreshes on a schedule.
- Store the key in Script Properties or a Power Query parameter — never in a shared cell.
Accountants, importers and analysts live in spreadsheets. Copying the dollar rate by hand every morning is error-prone. This guide shows how to get live exchange rates in Google Sheets and Excel directly from the EZRate API, without third-party add-ons.
EZRATE function below, save your key in Script Properties and use =EZRATE("usd","sell") in any cell. Excel: Data → Get Data → From Web (Advanced), enter https://api.ezrate.me/v1/rates?symbols=usd,eur,g18 with an X-API-Key header, expand data and set a refresh interval.Part of the Iranian Rial exchange rate API guide.
Google Sheets with Apps Script
1. Save the key privately
In Apps Script: Project Settings → Script Properties → add EZRATE_KEY. People you share the sheet with as viewers cannot see it.
2. Add the function
/**
* Live Iranian market rate.
* @param {string} symbol e.g. "usd", "eur", "g18", "emami", "usdt"
* @param {string} side "sell" (default), "buy" or "change_pct"
* @customfunction
*/
function EZRATE(symbol, side) {
side = side || "sell";
const all = ezrateAll_();
const r = all[String(symbol).toLowerCase()];
if (!r) throw new Error("Unknown symbol " + symbol);
return r[side];
}
function ezrateAll_() {
const cache = CacheService.getScriptCache();
const hit = cache.get("ezrate");
if (hit) return JSON.parse(hit);
const key = PropertiesService.getScriptProperties().getProperty("EZRATE_KEY");
const res = UrlFetchApp.fetch(
"https://api.ezrate.me/v1/rates?symbols=usd,eur,aed,try,g18,emami,rob,usdt",
{ headers: { "X-API-Key": key }, muteHttpExceptions: true });
if (res.getResponseCode() !== 200) throw new Error("EZRate " + res.getResponseCode());
const map = {};
JSON.parse(res.getContentText()).data.forEach(x => map[x.symbol] = x);
cache.put("ezrate", JSON.stringify(map), 300); // 5 minutes
return map;
}One cached request serves every EZRATE() cell for five minutes, so a sheet with hundreds of formulas still uses a handful of requests per hour.
3. Refresh on a schedule
Custom functions recalculate when inputs change. To force a refresh, add a time-driven trigger that writes the current time into a helper cell referenced by your formulas, e.g. =EZRATE("usd","sell",$Z$1) with a third ignored parameter.
Excel with Power Query
- Data → Get Data → From Other Sources → From Web → Advanced.
- URL:
https://api.ezrate.me/v1/rates?symbols=usd,eur,aed,g18,emami. - HTTP request header:
X-API-Key= your key. - In the editor, drill into
data, convert the list to a table and expand the columns you need. - Close & Load, then Query Properties → Refresh every 5 minutes (or on open).
let
Key = Excel.CurrentWorkbook(){[Name="ApiKey"]}[Content]{0}[Column1],
Source = Json.Document(Web.Contents("https://api.ezrate.me/v1/rates",
[Query = [symbols = "usd,eur,aed,g18,emami"], Headers = [#"X-API-Key" = Key]])),
Rows = Table.FromRecords(Source[data]),
Keep = Table.SelectColumns(Rows, {"symbol", "name", "buy", "sell", "change_pct", "updated_at"})
in
KeepHistorical data in a sheet
function EZHISTORY(symbol, from, to) {
const key = PropertiesService.getScriptProperties().getProperty("EZRATE_KEY");
const url = "https://api.ezrate.me/v1/history/" + symbol + "?interval=1d&from=" + from + "&to=" + to;
const data = JSON.parse(UrlFetchApp.fetch(url, { headers: { "X-API-Key": key } }).getContentText()).data;
return [["date", "close"]].concat(data.map(c => [new Date(c.t), c.c]));
}Use =EZHISTORY("usd","2026-01-01","2026-10-01") to spill a daily series. For research workflows see historical USD/IRR data.
Practical uses in a spreadsheet
- Price lists: a column of USD costs multiplied by
=EZRATE("usd","sell")and your margin gives a live Toman price list. - Inventory valuation: value foreign-currency stock at today’s rate for management reports.
- Daily rate log: a time-driven trigger appends the day’s rates to a log sheet for accounting.
- Gold shop sheet: weight ×
=EZRATE("g18")plus making charge for quick quotes.
For accounting use, store the rate and its timestamp next to every converted amount instead of relying on a formula that changes tomorrow; copy values into the log, not formulas.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
#ERROR! with “EZRate 401” | Key missing or wrong in Script Properties |
#ERROR! with “EZRate 429” | Too many uncached calls; keep CacheService and avoid volatile triggers every few seconds |
| Values never change | Custom functions recalculate only on input change; add the refresh trigger described above |
| Excel asks for credentials | Choose “Anonymous” access; the key is sent in the header, not as a login |
| Numbers look 10× too big | The sheet expects Toman but you requested Rial (or the reverse) |
For shared company sheets, consider a separate key with its own quota so a broken sheet cannot use up the quota of your production systems. You can see each key’s consumption with the /usage endpoint.
Related live rates: US dollar rate, 18K gold price, Emami coin price.
Comments (0)
Comments are shown after review. Sign-in is needed to send.


