IMPORTDATA fetches a web address and cannot send a header. This API reads the key from the Authorization header, so IMPORTDATA gets a 401. Apps Script can send headers with UrlFetchApp, so the steps below add a COINPRICE function to your sheet.
Get a key
Sign up for a free key. The Free plan has 50,000 calls a month and 100 calls a minute, needs no card, and every plan stops at its limit with no extra charge.
Store the key
- In your sheet, open Extensions, then Apps Script.
- Open Project Settings and scroll to Script properties.
- Add a property named
COINPRICE_API_KEYand paste your key as its value.
The key now lives in the script project. It is not in any cell, so sharing the sheet does not share the key. Anyone you give edit access to the script can read it.
Add the function
Replace the contents of Code.gs with this and save.
const COINPRICE_API = 'https://api.coinprice.dev/v2'/** * Latest prices: one row per coin with its id, USD price, 24-hour change and the time of the price. * @param {string} ids Coin ids separated by commas, or a range of ids. * @return {Array<Array>} Rows of id, price, change, time. * @customfunction */function COINPRICE(ids) { const key = PropertiesService.getScriptProperties().getProperty('COINPRICE_API_KEY') const list = String(ids).split(',').map((id) => id.trim().toLowerCase()).filter(Boolean) const url = COINPRICE_API + '/simple/price?vs_currencies=usd&include_24hr_change=true&include_last_updated_at=true&ids=' + encodeURIComponent(list.join(',')) const res = UrlFetchApp.fetch(url, { headers: { Authorization: 'Bearer ' + key }, muteHttpExceptions: true }) const body = JSON.parse(res.getContentText()) if (res.getResponseCode() !== 200) throw new Error(body.message) return list .filter((id) => body[id]) .map((id) => [id, body[id].usd, body[id].usd_24h_change === null ? '' : body[id].usd_24h_change / 100, new Date(body[id].last_updated_at * 1000)])}The first time you use the function Google asks you to allow it to connect to an external service. Accept, and the function runs.
Use it in a cell
Type =COINPRICE("bitcoin,ethereum,solana") in A2. The function fills a block of three rows and four columns: coin id, USD price, 24-hour change and the time of the price. This is the value it returned when we ran it against the live API.
[ ["bitcoin",60439.05,-0.012396,"2026-11-24T04:32:05.000Z"], ["ethereum",1698.455891,-0.018186,"2026-11-24T04:32:05.000Z"], ["solana",71.71847498,0.00605,"2026-11-24T04:32:05.000Z"]]The change comes back as a fraction, so format column C as a percentage. The change cell is empty when the API has null for it, which happens when there is not enough history. Format column D as a date and time. To read the ids from cells, pass the range: =COINPRICE(A2:A10).
A coin id the API does not know is left out of the result instead of raising an error. Coin ids are in /v2/coins/list, for example bitcoin, not btc. An answer with no known id still counts as a call. Put every coin in one call: one request prices up to 250 coins and counts as one call.
Keep prices fresh
A custom function recalculates when its inputs change, not on a clock. To refresh on a schedule, add a function that writes the result into a sheet named Prices, and run it from a time trigger.
function refreshPrices() { const rows = COINPRICE('bitcoin,ethereum,solana') SpreadsheetApp.getActive().getSheetByName('Prices').getRange(2, 1, rows.length, 4).setValues(rows)}- In Apps Script, open Triggers and choose Add Trigger.
- Pick
refreshPrices, Time-driven, then Minutes timer, every minute.
One call a minute is 43,200 calls a month, inside the 50,000 on the Free plan.
Errors
A wrong key throws an error with the API message, which Sheets shows in the cell.
That API key is not valid.The other error bodies are listed in the API reference.