Oil Price API Documentation - Quick Start in 5 Minutes | REST API
GitHub
GitHub

n8n Integration

Build powerful, self-hosted oil price automation workflows with n8n. As an open-source workflow automation platform, n8n gives you complete control over your commodity data pipelines while integrating with hundreds of applications.


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 (unlimited workflows)
  • 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,NATURAL_GAS_USD

Headers:

NameValue
AuthorizationToken YOUR_API_KEY
Content-Typeapplication/json

Options:

  • Response Format: JSON
  • Full Response: Off

Step 4: Process the Data

Add a Code node to transform the data:

// Transform API response for downstream use
const items = $input.first().json.data.items;

return items.map(item => ({
  json: {
    commodity: item.code,
    price: item.price,
    change: item.change_percent,
    updated: item.updated_at,
    timestamp: new Date().toISOString()
  }
}));

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.timestamp }}
    • Commodity: {{ $json.commodity }}
    • Price: {{ $json.price }}
    • Change: {{ $json.change }}

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.timestamp }}
  • On Conflict: Update

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:

    • Name: OilPriceAPI
    • Name: Authorization
    • 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',
    created_at: new Date().toISOString()
  }
}));

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
OILPRICEAPI_KEY=opa_live_your_key

Access in workflows:

const apiKey = process.env.OILPRICEAPI_KEY;

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

FAQ

Is n8n free to use for oil price automation?

n8n is fair-code licensed. Self-hosting is free for any use. n8n Cloud has a free tier with 5 active workflows and limited executions. Paid plans start at $20/month.

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
  • Zapier Integration
  • Make Integration
Last Updated: 12/28/25, 12:24 AM