Spreadsheet workflow
Automatically update fuel costs in Excel or Google Sheets
If your team already relies on Excel or Google Sheets for fuel assumptions, surcharge inputs, recurring reports, or internal dashboards, the goal is not more spreadsheet work. The goal is to pull source-backed diesel inputs and keep the workflow honest about timestamps.
See the spreadsheet workflow
One API key, one benchmark, one spreadsheet workflow your team can keep using.
Replace recurring diesel-price copy/paste with a repeatable API pull
Keep fuel-cost and surcharge inputs current without rebuilding your sheet
Start with one diesel benchmark code, then expand only when stable
Source-backed diesel inputs
Build the surcharge workflow around the data source
OilPriceAPI can provide the diesel input. Your spreadsheet should still own the contract logic: baseline price, MPG, route miles, index choice, adjustment period, and customer-specific terms.
Retail diesel for surcharge workflows
- Coverage
- National DOE/EIA on-highway retail diesel via DIESEL_RETAIL_USD, regional/PADD diesel where configured, and state-level retail diesel codes such as DIESEL_RETAIL_STATE_TX_USD where available.
- Source
- National and PADD diesel prices use EIA weekly retail diesel sources. State-level diesel codes use AAA state average retail diesel source paths.
- Cadence
- National/PADD retail diesel is weekly source data. State diesel codes are source-observed state averages. Use returned timestamps and source fields instead of promising live freshness.
- First endpoint
- /v1/prices/latest?by_code=DIESEL_RETAIL_USD
Response fields to inspect
- code, price/value, currency, and unit
- source and created_at or timestamp fields
- freshness or status fields when returned
- state code where a state-level diesel input is used
Keep visible
- Not a legal, tariff, or contract authority
- EIA national/PADD diesel is weekly, not real-time
- No universal surcharge formula is implied
- Excel add-in reliability remains separate from this API workflow
First call: national and state diesel
Use the national DOE/EIA diesel code first. Add state-level diesel only when your contract or internal model calls for regional input.
Request
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=DIESEL_RETAIL_USD" \
-H "Authorization: Token YOUR_API_KEY"
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=DIESEL_RETAIL_STATE_TX_USD" \
-H "Authorization: Token YOUR_API_KEY"Expected shape
{
"status": "success",
"data": {
"code": "DIESEL_RETAIL_USD",
"price": 3.68,
"currency": "USD",
"unit": "gallon",
"source": "eia_api",
"created_at": "2026-05-05T14:00:00Z"
}
}
{
"status": "success",
"data": {
"code": "DIESEL_RETAIL_STATE_TX_USD",
"price": 3.22,
"currency": "USD",
"unit": "gallon",
"source": "aaa",
"created_at": "2026-05-10T12:00:00Z"
}
}- Apply your own baseline, MPG, mileage, and contract terms in the sheet.
- Keep source and timestamp cells visible next to the price input.
- Use weekly cadence expectations for EIA national/PADD diesel.
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("DIESEL_RETAIL_USD")
=OPA_LATEST("DIESEL_RETAIL_STATE_TX_USD")Keep it narrow at first: one sheet, one benchmark, one report. Expand once the workflow is stable.
Option B
Excel: use the OilPrice add-in
If your org standardizes on Excel, use the add-in formula path: set the API key once, reference benchmark codes in cells, and recalculate inside the workbook.
1) Start with one benchmark formula
Keep the first spreadsheet small enough to support.
=OILPRICE.PRICE("DIESEL_RETAIL_USD")
=OILPRICE.PRICE(A2)2) Recalculate in Excel
Change the input cell and refresh the workbook.
The goal is a supportable spreadsheet workflow: one key setup, visible input cells, and plain worksheet errors for auth, quota, tier, or no-data states.
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.