guides

Sports odds in Google Sheets: best prices with Apps Script

By · Published · Updated · 6 min read

To get sports odds into Google Sheets, a short Apps Script calls the PricedOdds API with UrlFetchApp and writes the rows to a tab. The script below reads GET /v1/best for the NBA and writes one row per selection: the matchup, the market, the side, the line, the book with the best price, that price in American and decimal odds, and the no-vig fair price. In our run it wrote 98 rows for 31 games from 2 API calls.

What do I need to put odds in Google Sheets?

  • A Google Sheet, and its script editor under Extensions > Apps Script.
  • A PricedOdds API key. The script reads it from a script property, so the key is not in the code: in the Apps Script editor, Project Settings, then Script Properties and Edit script properties (Google's guide). Name the property PRICEDODDS_API_KEY and paste your key as the value. Script properties are shared by everyone who can edit the script, so do not share the script with people who should not use your key.
  • Nothing to install. fetch is not available in Apps Script; UrlFetchApp.fetch makes the HTTP request (UrlFetchApp reference).

How does the script work?

  1. It calls GET /v1/best?league=nba&market=moneyline@game,spread@game,total@game with the header Authorization: Bearer and your key. Each row of the answer is one game, market and period, and carries for each selection the best price across the books on your plan and the fair price without the margin.
  2. The answer comes in pages: when next is not empty, the script asks again with cursor set to it. In our run the NBA took 2 pages.
  3. It turns each selection into a sheet row and writes all of them at once with setValues, which is much faster than one cell at a time.
  4. It clears and rewrites the same tab on every run, and writes the asOf time of the API answer under the table, so the sheet always shows how old its prices are.

muteHttpExceptions: true makes UrlFetchApp return the answer instead of throwing on an HTTP error, so the script can stop with the status and the start of the body, which says what went wrong.

What is the code?

// sheets-best-prices.gs: best price per selection across books into a Google Sheet, with the no-vig fair price. Google Apps Script (V8).
// Setup: Extensions > Apps Script, paste this file, add the script property PRICEDODDS_API_KEY, run refreshBestPrices once.
const BASE = 'https://api.pricedodds.com/v1';
const LEAGUE = 'nba';
const MARKETS = 'moneyline@game,spread@game,total@game';

function refreshBestPrices() {
  const key = PropertiesService.getScriptProperties().getProperty('PRICEDODDS_API_KEY');
  if (!key) throw new Error('Add the script property PRICEDODDS_API_KEY first');
  const params = { headers: { Authorization: 'Bearer ' + key }, muteHttpExceptions: true };

  // 1. Every page of GET /v1/best: one row per game, market and period, with the best price of each selection
  const data = [];
  let cursor = '';
  let asOf = '';
  do {
    const url = BASE + '/best?league=' + LEAGUE + '&market=' + encodeURIComponent(MARKETS) + (cursor ? '&cursor=' + encodeURIComponent(cursor) : '');
    const res = UrlFetchApp.fetch(url, params);
    if (res.getResponseCode() !== 200) throw new Error('PricedOdds answered ' + res.getResponseCode() + ': ' + res.getContentText().slice(0, 200));
    const body = JSON.parse(res.getContentText());
    data.push.apply(data, body.data);
    asOf = body.asOf;
    cursor = body.next;
  } while (cursor);

  // 2. One sheet row per selection
  const rows = [['Matchup', 'Starts (UTC)', 'Market', 'Side', 'Line', 'Best book', 'Best American', 'Best decimal', 'Fair American', 'Fair probability']];
  for (const r of data) {
    for (const s of r.selections) {
      rows.push([r.matchup, r.startsAt, r.market + ' ' + r.period, s.side, s.line === null ? '' : s.line,
        s.best.book, s.best.american, s.best.decimal, s.fair ? s.fair.american : '', s.fair ? s.fair.prob : '']);
    }
  }

  // 3. Write the tab named after the league, and the time of the data under the table
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName(LEAGUE.toUpperCase()) || ss.insertSheet(LEAGUE.toUpperCase());
  sheet.clearContents();
  sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
  sheet.getRange(rows.length + 2, 1).setValue('Prices as of ' + asOf + ' (UTC)');
  sheet.setFrozenRows(1);
}

// A PricedOdds menu in the sheet, to refresh by hand
function onOpen() {
  SpreadsheetApp.getUi().createMenu('PricedOdds').addItem('Refresh best prices', 'refreshBestPrices').addToUi();
}

// Run once to refresh every 15 minutes on its own
function installTrigger() {
  ScriptApp.newTrigger('refreshBestPrices').timeBased().everyMinutes(15).create();
}

To use it: paste it in the Apps Script editor, save, add the script property, choose refreshBestPrices and click Run. The first run asks you to authorize the script. Reload the sheet and a PricedOdds menu appears with Refresh best prices.

What did a real run return?

We ran the script on November 25, 2026, 14:17 UTC, against live NBA prices. Its first rows:

Matchup | Starts (UTC) | Market | Side | Line | Best book | Best American | Best decimal | Fair American | Fair probability
MIA @ PHI | 2026-11-25T22:00:00.000Z | moneyline game | home |  | polymarket | -113 | 1.887 | -111 | 0.5272
MIA @ PHI | 2026-11-25T22:00:00.000Z | moneyline game | away |  | kalshi | 113 | 2.13 | 112 | 0.4728
MIA @ PHI | 2026-11-25T22:00:00.000Z | spread game | home | -1.5 | polymarket | -104 | 1.961 | -102 | 0.5056
MIA @ PHI | 2026-11-25T22:00:00.000Z | spread game | away | 1.5 | prophetx | 104 | 2.04 | 102 | 0.4944
MIA @ PHI | 2026-11-25T22:00:00.000Z | total game | over | 237.5 | hardrock | -105 | 1.952 | -105 | 0.5125
MIA @ PHI | 2026-11-25T22:00:00.000Z | total game | under | 237.5 | prophetx | 106 | 2.06 | 105 | 0.4875

Under the table it wrote Prices as of 2026-11-25T14:17:48.557Z (UTC). These are prices of one evening, shown as an example and not as current prices.

How we tested it. We did not run it inside Google Sheets. We ran the same file, unchanged, in Node 24 with small stand-ins for the four Apps Script services it calls: UrlFetchApp.fetch made the real HTTP request to the API, PropertiesService returned the key, and SpreadsheetApp and ScriptApp kept the sheet, the menu and the trigger in memory. We ran refreshBestPrices twice: each run made 2 API calls, all answered 200, and the second run rewrote the same NBA tab instead of adding one. So the API calls, the paging and the rows ran for real; the Google side ran against a stand-in.

How do I refresh the odds automatically?

Run installTrigger once. It creates a time-driven trigger that runs refreshBestPrices every 15 minutes. Google allows 1, 5, 10, 15 or 30 minutes for this kind of trigger (ClockTriggerBuilder). Google also sets daily limits: on a personal Google account, read on November 25, 2026, 20,000 URL Fetch calls a day, 6 minutes per execution and 90 minutes of total trigger runtime a day (quotas). At 2 calls every 15 minutes, one league uses 192 calls a day. The API has its own rate limit for each plan, in requests per second, on the pricing page; a refresh every few minutes stays far below it.

A sheet refreshed every few minutes is fine for line shopping by hand. For prices that change by the second, a spreadsheet is the wrong tool: use the WebSocket, as in the JavaScript WebSocket tutorial.

How do I change the league or the markets?

  • LEAGUE: any league id from the coverage page, such as nfl or nhl. Each league gets its own tab, so you can copy the function once per league.
  • MARKETS: a comma list of market@period, such as moneyline@game or total@1h. The markets and periods of each league are on the coverage page and in the docs.
  • Books: /v1/best compares the books on your plan; add books=draftkings,fanduel to compare only some of them.

To check a price by hand, the no-vig calculator and the implied probability calculator take the numbers of a row.

What are the limits of odds in a spreadsheet?

The sheet holds the prices of its last refresh, not live prices, and the asOf line says when that was. Each refresh replaces the tab, so the sheet keeps no history; the API returns current prices, not history, so to keep old prices you have to copy them to another tab before each refresh. A best price is the best of the books on your plan at that moment, and in play it can be a price that another book has already moved. Nothing here is betting advice.

The market key finder gives the key to put in the markets parameter of your sheet. To show the same best prices on a web page instead of a sheet, see a server-rendered odds table for your website. To turn a saved response into a file you can import, convert the JSON to CSV.

FAQ

Can I use IMPORTDATA instead of a script?

No. The API takes the key only in the Authorization header, and IMPORTDATA cannot send headers, so a short Apps Script is the simple way.

Where should the API key go?

In a script property named PRICEDODDS_API_KEY, not in the code and not in a cell, where anyone who can see the sheet would read it.

Does it work in Excel?

Not this script: Apps Script runs in Google Sheets, not in Excel. The API answer is the same JSON in any tool that can send an Authorization header.

Where do I start?

Paste the script, add your key and run refreshBestPrices once to see the rows. The fields are in the docs and the books and leagues are on the coverage page. Every plan starts with a 3-day free trial with a $1 card verification that is refunded immediately. The plan you pick at signup is charged from day 4 unless you cancel before the trial ends. See pricing or create an account.