Documentation

API Documentation

Everything you need to integrate with the ClauseHub Energy API. Endpoints, authentication, response formats, and more.

Quick Start

Make your first API call in under 60 seconds. The public search endpoint requires no authentication.

Step 1 — Search tariffs (no auth required)

curl
curl -s "https://api.clausehub.net/energy/tariffs/search/public" \
  -H "Accept: application/vnd.api+json"

Step 2 — Filter by region and tariff type

curl
curl -s "https://api.clausehub.net/energy/tariffs/search/public?filter[tariffType]=Fixed&filter[region]=South%20East" \
  -H "Accept: application/vnd.api+json"

Step 3 — Get an API key for full access

The public endpoint returns read-only search results. For full CRUD access, version history, and bulk operations, sign up for an API key.

curl — authenticated
curl -s "https://api.clausehub.net/energy/suppliers" \
  -H "Accept: application/vnd.api+json" \
  -H "Authorization: Bearer <your-jwt-token>"
Search Playground API Changelog Interactive Explorer Download Postman Collection

Reference

The ClauseHub Energy API provides standardised access to UK energy tariff data in JSON:API format. All requests and responses use the application/vnd.api+json content type.

Quick Reference

Base URL https://api.clausehub.net/energy
Format JSON:API (application/vnd.api+json)
Authentication Supabase JWT Bearer token
Rate Limit (admin) 120 requests / minute
Rate Limit (supplier) 60 requests / minute
Rate Limit (consumer) 120 requests / minute
OpenAPI Spec GET /schema

Authentication

All authenticated endpoints require a valid Supabase JWT token passed as a Bearer token in the Authorization header. Tokens are issued by the ClauseHub authentication service and encode the user's role and permissions.

Roles

The API enforces role-based access control with three roles:

  • admin — Full read/write access to all resources, including lookup tables and system configuration. Rate limited to 120 requests per minute.
  • supplier — Read/write access to their own supplier record and tariffs. Rate limited to 60 requests per minute.
  • consumer — Read-only access to published tariff data and public search endpoints. Rate limited to 120 requests per minute.

Example Request

HTTP
GET /energy/suppliers HTTP/1.1
Host: api.clausehub.net
Accept: application/vnd.api+json
Authorization: Bearer <your-jwt-token>

If the token is missing or invalid, the API returns a 401 Unauthorized error. If the token is valid but the user lacks permission for the requested operation, the API returns 403 Forbidden.

Endpoints

All endpoints are relative to the base URL https://api.clausehub.net/energy.

Method Endpoint Description
Health & Schema
GET /health Health check
GET /schema OpenAPI specification
Suppliers
GET /suppliers List all suppliers
POST /suppliers Create a supplier
GET /suppliers/{id} Get a single supplier
PATCH /suppliers/{id} Update a supplier
DELETE /suppliers/{id} Delete a supplier
GET /suppliers/{id}/versions List supplier version history
Tariffs
GET /suppliers/{id}/tariffs List tariffs for a supplier
POST /suppliers/{id}/tariffs Create a tariff
GET /suppliers/{id}/tariffs/{tariffId} Get a single tariff
PATCH /suppliers/{id}/tariffs/{tariffId} Update a tariff
DELETE /suppliers/{id}/tariffs/{tariffId} Delete a tariff
POST /suppliers/{id}/tariffs/bulk Bulk create tariffs
GET /suppliers/{id}/tariffs/{tariffId}/versions List tariff version history
Search
GET /tariffs/search Search tariffs (authenticated)
GET /tariffs/search/public Search tariffs (public, no auth)
GET /tariffs/recent List recently updated tariffs
Lookup Tables
GET /tariff-types List tariff types
POST /tariff-types Create a tariff type
GET /tariff-types/{id} Get a tariff type
PATCH /tariff-types/{id} Update a tariff type
DELETE /tariff-types/{id} Delete a tariff type
GET /tariff-types/{id}/versions Tariff type version history
GET /fuel-types List fuel types
POST /fuel-types Create a fuel type
GET /fuel-types/{id} Get a fuel type
PATCH /fuel-types/{id} Update a fuel type
DELETE /fuel-types/{id} Delete a fuel type
GET /fuel-types/{id}/versions Fuel type version history
GET /payment-types List payment types
POST /payment-types Create a payment type
GET /payment-types/{id} Get a payment type
PATCH /payment-types/{id} Update a payment type
DELETE /payment-types/{id} Delete a payment type
GET /payment-types/{id}/versions Payment type version history
GET /regions List regions
POST /regions Create a region
GET /regions/{id} Get a region
PATCH /regions/{id} Update a region
DELETE /regions/{id} Delete a region
GET /regions/{id}/versions Region version history

Response Format

All responses conform to the JSON:API specification. List endpoints return a top-level links object for pagination alongside a data array.

JSON
{
  "links": {
    "self": "/energy/suppliers?page[number]=1&page[size]=20",
    "first": "/energy/suppliers?page[number]=1&page[size]=20",
    "last": "/energy/suppliers?page[number]=3&page[size]=20",
    "next": "/energy/suppliers?page[number]=2&page[size]=20",
    "prev": null
  },
  "data": [
    {
      "type": "suppliers",
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "attributes": {
        "name": "Octopus Energy",
        "version": 1,
        "status": "active",
        "createdAt": "2025-10-15T09:30:00Z",
        "updatedAt": "2025-10-15T09:30:00Z"
      }
    }
  ]
}

Single-resource endpoints return the same structure, but data is an object rather than an array.

Versioning

The Energy API implements immutable versioning for full audit traceability. Every resource carries a version field that increments on each change.

How It Works

  • Create — A new resource is created at version 1 with status active.
  • Update (PATCH) — The existing row is preserved as-is. A new row is inserted with an incremented version number and the updated fields. The previous version remains accessible via the /versions endpoint.
  • Delete (DELETE) — A new version is created with status archived. No data is physically deleted. The full history remains available.

Accessing History

Every resource type exposes a /versions endpoint that returns the complete version history, ordered by version number descending. This provides a full audit trail of every change made to the resource.

HTTP
GET /energy/suppliers/a1b2c3d4/versions

# Returns all versions of this supplier, newest first

Errors

Errors follow the JSON:API error format. The response body contains an errors array with one or more error objects:

JSON
{
  "errors": [
    {
      "status": "422",
      "title": "Unprocessable Entity",
      "detail": "The field 'name' is required.",
      "source": {
        "pointer": "/data/attributes/name"
      }
    }
  ]
}

Status Codes

Code Meaning Description
401 Unauthorized Missing or invalid JWT token.
403 Forbidden Valid token, but insufficient permissions for this operation.
404 Not Found The requested resource does not exist.
409 Conflict A resource with the same unique identifier already exists.
415 Unsupported Media Type Request Content-Type must be application/vnd.api+json.
422 Unprocessable Entity Validation failed. Check the detail and source fields.
429 Too Many Requests Rate limit exceeded. Wait and retry.
500 Internal Server Error An unexpected error occurred on the server.

Interactive Explorer

Browse the full API schema interactively. Try endpoints, view request/response schemas, and explore the data model.