Get oil prices in Excel with an add-in or Power Query
Use the preview OilPrice Excel add-in for worksheet formulas, or connect Power Query to the API for a table you refresh once a day. Both paths require an OilPriceAPI account and API key.
Published · Updated
Add-in formulas
Install the preview add-in using the Excel install guide, save your API key in its pane, then enter a formula. Mac Excel 16.110.2 has a recorded runtime check; Excel on the web and Windows have install paths but no recorded runtime check yet.
Power Query: a daily price table
In Excel, create a text parameter named OilPriceAPIKey, then choose Data → Get Data → Blank Query → Advanced Editor and paste this query. It requests the latest Brent record with the required authorization header and returns a table including the source timestamp. Replace BRENT_CRUDE_USD with WTI_USDor DIESEL_USD for those series. The three codes returned 200 with matching records in the live API on October 31, 2026.
let
Response = try Json.Document(Web.Contents(
"https://api.oilpriceapi.com",
[RelativePath = "v1/prices/latest",
Query = [by_code = "BRENT_CRUDE_USD"],
Headers = [Authorization = "Token " & OilPriceAPIKey]]
)),
Data = if Response[HasError] then
error "OilPriceAPI refresh failed. Check your API key, plan access, and rate limit."
else if not Record.HasFields(Response[Value], {"status", "data"}) then
error "OilPriceAPI returned no price data. Check the code and retry."
else if Response[Value][status] <> "success"
or not Value.Is(Response[Value][data], type record) then
error "OilPriceAPI returned no price data. Check the code and retry."
else Response[Value][data],
Prices = Table.FromRecords({Data})
in
PricesRefresh the query once per day for a daily workbook. If refresh fails, check the key after a 401 response, plan access after a 403, and the retry window after a 429. The query raises an error when the request fails or the response lacks price data. Read the returned source timestamp and stale flag before treating a price as current. Keep your API key private; do not share a workbook containing a populated key parameter.
For installation details and the latest platform support, see theExcel integration page.
Continue with your preferred tool
The same API works in Google Sheets,Python, and Node.js. Keep the source timestamp with every value when you compare them.
For endpoints and response fields, see the API documentation.
Get an API key