To get an oil price alert, create one with POST /v1/alerts: a commodity code, a condition and a threshold. When the condition is met, OilPriceAPI emails your account address. Add a webhook_url and it also posts a signed alert.triggered event to your HTTPS endpoint. For Slack, that endpoint verifies the event and forwards a short text message to a Slack incoming webhook. OilPriceAPI has no native Slack integration; the Slack step is code you run.

Workflow: a price alert emails the account address and, with a registered webhook_url, posts a signed alert.triggered event to your relay, which forwards a text message to a Slack incoming webhook

Updated November 26, 2026. The threshold in the examples is illustrative, not a price call.

Create a price alert (email)

With your key in the OILPRICEAPI_KEY environment variable:

curl -X POST "https://api.oilpriceapi.com/v1/alerts" \
  -H "Authorization: Token $OILPRICEAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "price_alert": {
      "name": "Brent above 95",
      "commodity_code": "BRENT_CRUDE_USD",
      "condition_operator": "greater_than",
      "condition_value": 95.00,
      "cooldown_minutes": 60
    }
  }'

The operators are greater_than, less_than, equals, not_equals and between. cooldown_minutes (default 60) is the minimum gap between two triggers of the same alert. Each trigger sends an email to the address on your account. POST /v1/alerts/:id/test checks the alert against the current price and tells you whether it would trigger. How many alerts you can create depends on your plan.

Send the alert to a webhook

Webhook delivery has two parts. First register an HTTPS endpoint that subscribes to alert.triggered:

curl -X POST "https://api.oilpriceapi.com/v1/webhooks" \
  -H "Authorization: Token $OILPRICEAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://alerts.example.com/oilpriceapi",
    "events": ["alert.triggered"],
    "description": "Price alerts to Slack"
  }'

The response includes the endpoint's signing secret; store it as OILPRICEAPI_WEBHOOK_SECRET. Then create the alert with "webhook_url": "https://alerts.example.com/oilpriceapi", the exact URL you registered. If no active endpoint with that URL subscribes to alert.triggered for the alert's commodity, the API rejects the alert and says so. Email delivery continues alongside the webhook.

Webhooks are not on the Free or Developer plans: those accounts get 403 WEBHOOK_TIER_REQUIRED. On the pricing page, Fleet and Professional include 10 webhooks and Scale includes unlimited webhooks.

What the webhook receives

Each delivery is a JSON POST with these headers:

  • X-OilPriceAPI-Event: alert.triggered
  • X-OilPriceAPI-Event-ID: the event id, for de-duplication
  • X-OilPriceAPI-Signature: hex HMAC-SHA256 of the raw body, a ., and the timestamp, keyed with your endpoint secret
  • X-OilPriceAPI-Signature-Timestamp: Unix seconds

The body has this shape:

{
  "id": "6f1c2d7e-…",
  "event": "alert.triggered",
  "created_at": "2026-11-26T15:00:04Z",
  "data": {
    "alert_id": "…",
    "alert_name": "Brent above 95",
    "commodity_code": "BRENT_CRUDE_USD",
    "price_value": 95.12,
    "threshold_value": 95.0,
    "threshold_operator": "greater_than",
    "condition_met": true,
    "trigger_count": 1,
    "metadata": {},
    "observed_at": null,
    "timestamp": "2026-11-26T14:59:00Z"
  }
}

timestamp is when OilPriceAPI collected the price. observed_at is the date the price is for, when the source supplies one (for example a weekly EIA series); otherwise it is null. Verify the signature over the raw bytes you received, before parsing them, and reject timestamps more than five minutes old. Signing details are in the webhook verification guide.

Post the alert to Slack

A Slack incoming webhook expects a JSON body with a text (or blocks) field, and the OilPriceAPI event has neither, so you cannot point webhook_url straight at hooks.slack.com. Run a small relay at the URL you registered: it checks the signature, turns the event into one line of text, and posts that to Slack. Create the incoming webhook in your Slack workspace first and store its URL as SLACK_WEBHOOK_URL.

This relay uses only the Python standard library:

"""Relay OilPriceAPI alert webhooks to a Slack incoming webhook."""
import hashlib
import hmac
import json
import os
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.request import Request, urlopen

SECRET = os.environ["OILPRICEAPI_WEBHOOK_SECRET"].encode()
SLACK_URL = os.environ["SLACK_WEBHOOK_URL"]  # https://hooks.slack.com/services/...
seen_ids = set()  # use a database or cache in production


def valid_signature(body, timestamp, signature):
    if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > 300:
        return False  # missing, or older than 5 minutes
    expected = hmac.new(SECRET, body + b"." + timestamp.encode(),
                        hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature)


def slack_text(event):
    data = event["data"]
    observed = data.get("observed_at") or data["timestamp"]
    return (f"{data['alert_name']}: {data['commodity_code']} at "
            f"{data['price_value']} ({data['threshold_operator']} "
            f"{data['threshold_value']}), observed {observed}")


class Relay(BaseHTTPRequestHandler):
    def do_POST(self):
        body = self.rfile.read(int(self.headers.get("Content-Length", 0)))
        if not valid_signature(
            body,
            self.headers.get("X-OilPriceAPI-Signature-Timestamp", ""),
            self.headers.get("X-OilPriceAPI-Signature", ""),
        ):
            self.send_response(401)
            self.end_headers()
            return
        event = json.loads(body)
        if event.get("event") == "alert.triggered" and event["id"] not in seen_ids:
            message = json.dumps({"text": slack_text(event)}).encode()
            try:
                urlopen(Request(SLACK_URL, data=message,
                                headers={"Content-Type": "application/json"}),
                        timeout=10)
            except OSError:
                # Not delivered: answer 502 so OilPriceAPI retries the event.
                self.send_response(502)
                self.end_headers()
                return
            seen_ids.add(event["id"])  # only after Slack accepted it
        self.send_response(200)
        self.end_headers()


HTTPServer(("0.0.0.0", int(os.environ.get("PORT", "8080"))), Relay).serve_forever()

Serve it behind HTTPS (your load balancer or reverse proxy terminates TLS), because OilPriceAPI delivers only to HTTPS URLs. We tested it on November 26, 2026 with a locally signed event in the shape above: a valid event produced one Slack message, a bad signature got 401, a repeated event id was not posted twice, and when Slack was unreachable the relay answered 502 and posted the event on the next delivery. Keep the Slack URL secret; anyone with it can post to the channel.

Which channel to use

  • Email for a person who needs to know, with no code to run.
  • Webhook when a system should act: update a dashboard, open a ticket, recalculate a quote.
  • Slack when a team channel should see it; it is a webhook plus the relay above.

If you would rather poll on a schedule than receive events, webhooks vs polling for oil price updates compares the two. The price alerts and webhooks feature pages summarise each product, and the Price Alerts API reference covers creating and testing alerts. Its webhook payload example is out of date; the payload above is what the API sends.

New accounts get a 7-day trial with 10,000 requests and no credit card. After that, the Free plan is 50 requests/day. The Developer plan is $19/month for 10,000 requests/month.

Start a 7-day trial (10,000 requests, no credit card) · See the Developer plan ($19/month)

Building a product or workflow that needs oil prices?

Compare API plans, historical coverage, and support for your use case.

Explore API plans