Skip to main content

Spreadsheet workflow

Automatically update fuel costs in Excel or Google Sheets

If your team already relies on Excel or Google Sheets for fuel assumptions, recurring reports, or internal dashboards, the goal is not more spreadsheet work. The goal is to keep the workflow current automatically.

See the spreadsheet workflow

One API key, one benchmark, one spreadsheet workflow your team can keep using.

Replace recurring copy/paste with a repeatable API pull

Keep internal reporting inputs current without rebuilding your spreadsheet

Start with one benchmark code, then expand to more

Option A

Google Sheets: add a tiny Apps Script function

This is the simplest path when a team already lives in Sheets. You store your API key once, then call a function from cells.

1) Create a script

In Google Sheets: Extensions → Apps Script

// Store your key in Script Properties (do not hardcode it in sheets).
// 1) Apps Script → Project Settings → Script Properties
// 2) Add OPA_API_KEY = your key

function OPA_LATEST(code) {
  var props = PropertiesService.getScriptProperties();
  var apiKey = props.getProperty("OPA_API_KEY");
  if (!apiKey) return "Missing API key";

  var url = "https://api.oilpriceapi.com/v1/prices/latest?by_code=" + encodeURIComponent(code);
  var res = UrlFetchApp.fetch(url, {
    headers: { Authorization: "Token " + apiKey, Accept: "application/json" },
    muteHttpExceptions: true,
  });

  if (res.getResponseCode() !== 200) return "Unavailable";

  var json = JSON.parse(res.getContentText());
  if (!json || json.status !== "success" || !json.data || typeof json.data.price !== "number") return "Unavailable";

  return json.data.price;
}

2) Use it in a cell

Pick one benchmark code you care about first.

=OPA_LATEST("WTI_USD")
=OPA_LATEST("BRENT_CRUDE_USD")

Keep it narrow at first: one sheet, one benchmark, one report. Expand once the workflow is stable.

Option B

Excel: use Power Query (Get Data)

If your org already standardizes on Excel, Power Query gives you a predictable refresh workflow and a single place to manage the request.

1) Create a query for one benchmark

Data → Get Data → From Other Sources → Blank Query

let
  Code = "WTI_USD",
  ApiKey = "<YOUR_API_KEY>",
  Url = "https://api.oilpriceapi.com/v1/prices/latest?by_code=" & Uri.EscapeDataString(Code),
  Source = Json.Document(
    Web.Contents(
      Url,
      [Headers=[Authorization="Token " & ApiKey, Accept="application/json"]]
    )
  ),
  Price = Source[data][price]
in
  Price

2) Refresh on a schedule

Use Excel refresh settings appropriate to your workflow.

The goal is repeatability, not “refresh as fast as possible.” Tie refresh cadence to the reporting workflow the spreadsheet supports.

Notes

Guardrails

This page is intentionally narrow. It is meant to help a team automate one recurring spreadsheet workflow, not promise broad market coverage.

Use Authorization header format Token <key>.

Avoid copying example values into internal reports. Use the API pull as the source of truth for the sheet.

Start with one benchmark code, then expand only when the workflow is stable.

If you need a deeper integration, use this as a stepping stone and keep your next step narrow.