Skip to main content
📊 Google Sheets

Get Diesel Prices in Google Sheets

Use Apps Script to get real-time diesel prices. Works on desktop, mobile, and tablet.

Setup with Apps Script

Step 1: Open Apps Script Editor

  1. In Google Sheets, click Extensions → Apps Script
  2. Delete any existing code
  3. Paste the code below
function DIESEL_PRICE(stateCode) {
  const API_KEY = 'YOUR_API_KEY';
  const url = `https://api.oilpriceapi.com/v1/diesel-prices?state=${stateCode}`;

  const options = {
    'method': 'GET',
    'headers': {
      'Authorization': 'Bearer ' + API_KEY
    }
  };

  try {
    const response = UrlFetchApp.fetch(url, options);
    const data = JSON.parse(response.getContentText());
    return data.data.regional_average.price;
  } catch (error) {
    return 'Error: ' + error.message;
  }
}

Step 2: Use your custom function

Now you can use DIESEL_PRICE like any built-in Google Sheets function:

=DIESEL_PRICE("CA")

Ready to Get Started?

Get your free API key and start using diesel prices in Google Sheets today

Get Free API Key