OilPriceAPI Docs
Quick Start
API Reference
  • SDKs and languages
  • Tutorials
  • Articles
  • Documentation directory
  • Quick reference
  • API explorer
  • FAQ
  • Changelog
  • Status
  • Dashboard
GitHub
Quick Start
API Reference
  • SDKs and languages
  • Tutorials
  • Articles
  • Documentation directory
  • Quick reference
  • API explorer
  • FAQ
  • Changelog
  • Status
  • Dashboard
GitHub
  • Integrations

    • How to Get Oil Prices into Airtable (Automation Script)
    • Excel Add-in - Latest Oil Prices as Refreshable Formulas
    • Google Sheets Integration
    • Looker Studio Integration
    • Make (Integromat) Integration - Visual Oil Price Automation
    • How to Pull Oil Prices into n8n (HTTP Request + Schedule Trigger)
    • Notion Integration - Oil Price Dashboards & Databases
    • How to Get Oil Prices in Power BI with Power Query
    • Tableau Integration
    • How to Automate Oil Price Updates with Zapier (Webhooks by Zapier GET)

How to Pull Oil Prices into n8n

Add a Schedule Trigger, then an HTTP Request node with these settings. Each run returns the latest Brent price and its source timestamp:

FieldValue
MethodGET
URLhttps://api.oilpriceapi.com/v1/prices/latest
Queryby_code = BRENT_CRUDE_USD
AuthenticationGeneric Credential Type → Header Auth
CredentialName Authorization, Value Token YOUR_API_KEY

The node output (trimmed; a real response from 2026-11-26):

{
  "status": "success",
  "data": {
    "price": 96.53,
    "currency": "USD",
    "code": "BRENT_CRUDE_USD",
    "unit": "barrel",
    "as_of": "2026-11-26T18:29:00.000Z",
    "source_date": "2026-11-26",
    "changes": { "24h": { "amount": 2.82, "percent": 3.01 } }
  }
}

Use {{ $json.data.price }} and {{ $json.data.as_of }} in the next node. as_of is when the source observed the price; store it with every value. Always send an explicit by_code: a bare GET /v1/prices/latest returns BRENT_CRUDE_USD by default.

n8n workflow: Schedule Trigger, HTTP Request to /v1/prices/latest with by_code, IF on data.price, then Sheets, Postgres or Slack

The n8n page on oilpriceapi.com has an importable two-node workflow JSON. The rest of this guide covers several codes per request, self-hosting, templates and error handling.


Overview

n8n is a fair-code licensed workflow automation tool that can be self-hosted or used via n8n Cloud. It offers visual workflow building with the flexibility of custom code when needed.

Why Choose n8n for Oil Price Automation:

  • Self-hosted option for data sovereignty
  • No per-execution pricing when self-hosted
  • Custom JavaScript/Python code nodes
  • 400+ built-in integrations
  • Full API access and webhook support
  • Open-source community and extensions

Prerequisites

Before you begin:

  1. An active OilPriceAPI account with API key (Sign up)
  2. n8n installation (self-hosted or n8n Cloud)
  3. Access to destination systems (databases, apps, etc.)

n8n Installation Options

Option A: n8n Cloud

  • Sign up at n8n.cloud
  • No installation required

Option B: Docker Self-Hosted

docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  n8nio/n8n

Option C: npm Installation

npm install n8n -g
n8n start

Step-by-Step Workflow Setup

Step 1: Create a New Workflow

  1. Open n8n (default: http://localhost:5678)
  2. Click New Workflow
  3. Name it "Oil Price Automation"

Step 2: Add a Trigger Node

Option A: Schedule Trigger (Cron)

  1. Click Add first step
  2. Search for Schedule Trigger
  3. Configure:
    • Trigger Times: Add Item
    • Mode: Every Day
    • Hour: 8
    • Minute: 0

Option B: Webhook Trigger

  1. Search for Webhook
  2. Select Webhook node
  3. Copy the webhook URL for external triggers

Step 3: Add HTTP Request Node

  1. Click + after your trigger
  2. Search for HTTP Request
  3. Configure:

Settings:

FieldValue
MethodGET
URLhttps://api.oilpriceapi.com/v1/prices/latest

Query Parameters:

NameValue
by_codeBRENT_CRUDE_USD,WTI_USD

Authentication: Generic Credential Type → Header Auth, using a credential with Name Authorization and Value Token YOUR_API_KEY (see Using Credentials Securely).

With more than one code, the response holds an array in data.prices, and data.missing lists any requested code that has no current price. An unknown code returns HTTP 400 invalid_code unless you add partial=true. On the latest-price endpoint, up to 20 codes in one request count as one request (up to 10 when any of them is a futures contract; see pricing).

{
  "status": "success",
  "data": {
    "prices": [
      {
        "code": "BRENT_CRUDE_USD",
        "price": 96.53,
        "unit": "barrel",
        "as_of": "2026-11-26T18:29:00.000Z"
      },
      {
        "code": "WTI_USD",
        "price": 84.89,
        "unit": "barrel",
        "as_of": "2026-11-26T18:31:12.000Z"
      }
    ],
    "missing": []
  }
}

Step 4: Process the Data

Add a Code node to transform the data:

// One output item per code. Works for one code (data is an object)
// or several (data.prices is an array).
const data = $input.first().json.data;
const prices = Array.isArray(data.prices) ? data.prices : [data];

return prices.map((p) => ({
  json: {
    commodity: p.code,
    price: p.price,
    unit: p.unit,
    change: p.changes?.["24h"]?.percent ?? null,
    as_of: p.as_of,
    timestamp: new Date().toISOString(),
  },
}));

as_of is the source observation time; timestamp is when your workflow ran. Without a Code node, a Split Out node on data.prices gives the same one-item-per-code result.

Step 5: Send to Destination

Add destination nodes based on your needs:

Example: Send to Slack

  1. Add Slack node
  2. Connect your Slack account
  3. Configure:
    • Resource: Message
    • Operation: Send
    • Channel: #oil-prices
    • Text:
    Oil Price Update
    {{ $json.commodity }}: ${{ $json.price }}
    Change: {{ $json.change }}%
    

Step 6: Test and Activate

  1. Click Execute Workflow to test
  2. Review output at each node
  3. Toggle Active to enable the workflow

Workflow Templates

Template 1: Daily Price Report to Google Sheets

Track historical prices in a spreadsheet.

[Schedule Trigger] → [HTTP Request] → [Code] → [Google Sheets]
         (Daily 8 AM)      (Get Prices)    (Transform)   (Append Row)

Google Sheets Node Configuration:

  • Operation: Append
  • Spreadsheet: Your Oil Price Tracker
  • Sheet: Daily Prices
  • Mapping Mode: Map Each Column
    • Date: {{ $json.as_of }}
    • Commodity: {{ $json.commodity }}
    • Price: {{ $json.price }}
    • Change: {{ $json.change }}

To write the same rows to Airtable instead, swap the Google Sheets node for the Airtable node and use the field layout in the Airtable guide.

Template 2: Price Alert System

Send alerts when prices cross thresholds.

[Schedule Trigger] → [HTTP Request] → [Code] → [IF] → [Email/Slack]
         (Hourly)         (Get WTI)     (Check)   (> $80?)   (Alert)

IF Node Configuration:

  • Conditions:
    • Value 1: {{ $json.price }}
    • Operation: Larger
    • Value 2: 80

Template 3: Multi-Destination Distribution

Send prices to multiple systems simultaneously.

                                    → [Slack]
[Schedule] → [HTTP] → [Code] → [Split]
                                    → [Google Sheets]
                                    → [PostgreSQL]

Use the Split Out node to create parallel branches.

Template 4: Database Sync Pipeline

Maintain a local database of oil prices.

[Schedule] → [HTTP Request] → [Code] → [PostgreSQL: Upsert]

PostgreSQL Node Configuration:

  • Operation: Insert
  • Table: oil_prices
  • Columns:
    • commodity_code: {{ $json.commodity }}
    • price: {{ $json.price }}
    • change_percent: {{ $json.change }}
    • recorded_at: {{ $json.as_of }}
  • On Conflict: Update on (commodity_code, recorded_at), so a repeated observation is not stored twice

Advanced Techniques

Using Credentials Securely

Store your API key as a credential:

  1. Go to Settings > Credentials

  2. Click Add Credential

  3. Select Header Auth

  4. Configure:

    • Credential name: OilPriceAPI
    • Header Name: Authorization
    • Header Value: Token YOUR_API_KEY
  5. In HTTP Request node, select this credential under Authentication

Error Handling

Add error handling to your workflows:

  1. Click on any node
  2. Go to Settings
  3. Enable Continue on Fail

Or add an Error Trigger workflow:

[Error Trigger] → [Slack: Send Error Notification]

Retry Logic

Configure retries for API calls:

  1. Select HTTP Request node
  2. Go to Settings
  3. Retry On Fail: Enable
  4. Max Tries: 3
  5. Wait Between Tries: 5000 (ms)

Parallel Processing

Process multiple commodities in parallel:

// In Code node - create parallel requests
const commodities = [
  "BRENT_CRUDE_USD",
  "WTI_USD",
  "NATURAL_GAS_USD",
  "DIESEL_USD",
];

return commodities.map((code) => ({
  json: { commodity_code: code },
}));

Then use Split In Batches to process each.

Custom Functions

Create reusable functions:

// Price formatting function
function formatPrice(price, currency = "USD") {
  return new Intl.NumberFormat("en-US", {
    style: "currency",
    currency: currency,
  }).format(price);
}

// Calculate percentage change
function calculateChange(current, previous) {
  return (((current - previous) / previous) * 100).toFixed(2);
}

// Use in transformations
return $input.all().map((item) => ({
  json: {
    ...item.json,
    formatted_price: formatPrice(item.json.price),
    is_significant: Math.abs(item.json.change) > 2,
  },
}));

Integration Examples

PostgreSQL Database Sync

// Code node: Prepare for database insert
return $input.all().map((item) => ({
  json: {
    commodity_code: item.json.commodity,
    price: item.json.price,
    change_percent: item.json.change,
    source: "oilpriceapi",
    observed_at: item.json.as_of,
  },
}));

Webhook Endpoint for External Systems

Create an endpoint that returns current prices:

[Webhook] → [HTTP Request: Get Prices] → [Respond to Webhook]

External systems can call your n8n webhook to get formatted price data.

Email Digest with HTML Formatting

// Code node: Generate HTML email body
const items = $input.all();

let html = `
<h2>Daily Oil Price Report</h2>
<p>Generated: ${new Date().toLocaleString()}</p>
<table border="1" cellpadding="8">
  <tr>
    <th>Commodity</th>
    <th>Price</th>
    <th>Change</th>
  </tr>
`;

items.forEach((item) => {
  const changeColor = item.json.change >= 0 ? "green" : "red";
  html += `
  <tr>
    <td>${item.json.commodity}</td>
    <td>$${item.json.price}</td>
    <td style="color: ${changeColor}">${item.json.change}%</td>
  </tr>
  `;
});

html += "</table>";

return [{ json: { html_body: html } }];

Self-Hosting Best Practices

Environment Variables

Store sensitive data in environment variables:

# .env file for n8n
N8N_BASIC_AUTH_ACTIVE=true
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=secure_password

Keep the OilPriceAPI key in an n8n Header Auth credential rather than an environment variable: credentials are stored encrypted, and recent n8n versions block environment access from Code nodes by default.

Backup Workflows

Export workflows regularly:

# Export all workflows
n8n export:workflow --all --output=./backups/

# Export specific workflow
n8n export:workflow --id=1 --output=./backups/oil-price-workflow.json

Monitoring

Monitor your n8n instance:

  1. Enable execution logging
  2. Set up health check endpoints
  3. Use external monitoring (UptimeRobot, Datadog)
  4. Configure alerts for failed executions

Security Considerations

  • Use HTTPS for n8n access
  • Enable basic authentication
  • Restrict network access to n8n instance
  • Rotate credentials regularly
  • Use separate credentials for production

Troubleshooting

Workflow Not Triggering

  • Verify workflow is Active (toggle in top right)
  • Check Schedule Trigger timezone settings
  • Review execution history for errors

API Request Failing

  • Verify API key in credentials
  • Check URL and header format
  • Test endpoint in browser or curl first
  • Review n8n execution logs

Data Not Flowing Between Nodes

  • Click on connecting lines to see data
  • Use Debug node to inspect data
  • Check expression syntax in field mappings

Performance Issues

  • Use Split In Batches for large datasets
  • Add delays between API calls to respect rate limits
  • Optimize code nodes to avoid memory issues

Frequently Asked Questions

How do I authenticate OilPriceAPI in n8n?

n8n offers several ways to handle authentication:

Method 1: Direct Headers (Simple) In the HTTP Request node:

  1. Go to Headers section
  2. Add: Authorization: Token YOUR_API_KEY

Method 2: Credentials (Recommended)

  1. Go to Settings > Credentials
  2. Click Add Credential > Header Auth
  3. Configure:
    • Name: OilPriceAPI
    • Header Name: Authorization
    • Header Value: Token YOUR_API_KEY
  4. In HTTP Request nodes, select this credential

Credentials are encrypted and more secure than hardcoded values.

What's the rate limit when using n8n with OilPriceAPI?

OilPriceAPI limits depend on your plan. New accounts get a 7-day trial with 10,000 requests and no credit card. After that, the Free plan is 50 requests/day and the Developer plan is $19/month for 10,000 requests/month; higher plans are on the pricing page. One request can carry up to 20 latest-price codes. Configure n8n schedules to stay within limits:

PlanExample schedule (one request per run)Requests
FreeEvery hour24/day
DeveloperEvery 5 minutes~8,640/month

n8n tip: Since n8n doesn't charge per execution (self-hosted), you can run more frequently without cost concerns, but respect OilPriceAPI limits.

Can I automate price updates in n8n?

Yes, n8n provides flexible automation options:

Schedule Trigger:

  1. Add Schedule Trigger node
  2. Configure interval (minutes, hours, days)
  3. Set specific times (e.g., "Every day at 8 AM")

Cron Expression (Advanced):

0 8 * * 1-5    # Weekdays at 8 AM
0 */4 * * *    # Every 4 hours
*/30 * * * *   # Every 30 minutes

Webhook Trigger:

  • Create an endpoint that external systems can call
  • Useful for on-demand refreshes

Manual Trigger:

  • Click Execute Workflow for testing
  • Useful for backfilling data

What happens if the API call fails in n8n?

n8n provides comprehensive error handling:

Built-in Retry:

  1. Select the HTTP Request node
  2. Go to Settings
  3. Enable Retry On Fail
  4. Set Max Tries (e.g., 3)
  5. Set Wait Between Tries (e.g., 5000ms)

Error Handling Nodes:

  1. Add an Error Trigger workflow
  2. Catch errors from any workflow
  3. Send notifications via Slack/Email

Continue on Fail:

  • Enable in node settings to prevent workflow stoppage
  • Useful when processing multiple commodities

Error Workflow Example:

[Error Trigger] → [Set Error Details] → [Slack Notification]

Common errors:

  • 401: Invalid API key format (use Token YOUR_KEY)
  • 400 invalid_code: a code in by_code does not exist (the response suggests close matches)
  • 429: Rate limited (add Wait node, reduce frequency)
  • Timeout: Increase timeout in HTTP Request settings

Is n8n free to use for oil price automation?

n8n is fair-code licensed. The self-hosted Community Edition costs nothing to run for your own internal workflows; n8n Cloud is a paid service (see n8n pricing for current plans). OilPriceAPI requests count against your OilPriceAPI plan either way.

How does n8n compare to Zapier for oil price tracking?

n8n offers more flexibility with custom code, self-hosting options, and no per-execution pricing. Zapier is easier to set up but can become expensive with high-volume automations.

Can I run n8n on a Raspberry Pi?

Yes, n8n can run on a Raspberry Pi or any system with Node.js. For production use, ensure adequate memory (2GB+ recommended) and storage.

How do I handle API rate limits in n8n?

Use the Wait node between API calls, configure retry settings on HTTP Request nodes, or use Split In Batches with delays to space out requests.

Can I create a REST API using n8n?

Yes, use Webhook nodes with Respond to Webhook to create custom API endpoints. This is great for building internal services that aggregate oil price data.


Related Documentation

  • Authentication Guide
  • API Reference
  • Rate Limiting
  • n8n setup on oilpriceapi.com
  • Webhooks
  • Zapier Integration
  • Make Integration
  • Airtable Integration: log prices to an Airtable table (n8n has an Airtable node; the guide also has a no-n8n automation script)
Last Updated: 11/26/26, 7:51 PM
Prev
Make (Integromat) Integration - Visual Oil Price Automation
Next
Notion Integration - Oil Price Dashboards & Databases