EZRate
Sign in

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.

E
· Editorial team
Published 1 November 2026, 20:00 · 3 min read
Live Exchange Rates in Google Sheets and Excel via API (No Add-ons)
Key takeaways
  • 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.

i
EZRate API
This guide uses the EZRate currency and gold price API: full documentation, code samples and a free key are on the API page.
★
Short answer
Google Sheets: Extensions → Apps Script, paste the 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

javascript
/**
 * 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

  1. Data → Get Data → From Other Sources → From Web → Advanced.
  2. URL: https://api.ezrate.me/v1/rates?symbols=usd,eur,aed,g18,emami.
  3. HTTP request header: X-API-Key = your key.
  4. In the editor, drill into data, convert the list to a table and expand the columns you need.
  5. Close & Load, then Query Properties → Refresh every 5 minutes (or on open).
powerquery
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
    Keep
i
Key safety
If you store the key in a named cell, anyone with the workbook can read it. For shared workbooks, keep a separate low-privilege key, or point Power Query at your own proxy endpoint instead.

Historical data in a sheet

javascript
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.

US Dollar271,740Toman−0.02%

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

SymptomCause 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 changeCustom functions recalculate only on input change; add the refresh trigger described above
Excel asks for credentialsChoose “Anonymous” access; the key is sent in the header, not as a login
Numbers look 10× too bigThe 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.

Can I get live USD to IRR rates in Google Sheets?
Yes, with a short Apps Script custom function that calls the EZRate API and caches the result.
Do I need an add-on?
No. Apps Script in Sheets and Power Query in Excel are built in.
How do I keep my key private in Sheets?
Store it in Script Properties, not in a cell.
How often do the values refresh?
As often as your cache and triggers allow; every 5 minutes is a sensible default.
E
The EZRate editorial team writes guides and market analysis on currencies, gold and crypto based on real trading data.
All posts by author →

Comments (0)

Comments are shown after review. Sign-in is needed to send.

Related

API & Developers
Financial API Failover Strategy: Timeouts, 429s, Staleness and Fallbacks
API & Developers
Currency Exchange WebSocket API or REST Polling? A Node.js Guide
API & Developers
Historical USD to IRR Data: Free-Market Candles via API for Analysts