Schemas API

Schemas define the expected structure of webhook payloads using JSON Schema. Attach schemas to routes to validate incoming events before delivery.

Endpoints

MethodPathDescription
GET/api/schemasList schemas
POST/api/schemasCreate schema
GET/api/schemas/{id}Get schema
PATCH/api/schemas/{id}Update schema
DELETE/api/schemas/{id}Delete schema

Schema Object

{
  "id": "sch_abc123",
  "name": "GitHub Push Event",
  "description": "Validates GitHub push webhook payloads",
  "schema": {
    "type": "object",
    "required": ["ref", "repository", "pusher"],
    "properties": {
      "ref": { "type": "string" },
      "repository": {
        "type": "object",
        "required": ["full_name"],
        "properties": {
          "full_name": { "type": "string" }
        }
      },
      "pusher": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": { "type": "string" }
        }
      }
    }
  },
  "version": 1,
  "routeCount": 2,
  "createdAt": "2024-01-01T00:00:00Z",
  "updatedAt": "2024-01-15T10:30:00Z"
}

List Schemas

GET /api/schemas

Query Parameters

ParameterTypeDescription
pagenumberPage number (default: 1)
pageSizenumberItems per page (default: 20, max: 100)
searchstringSearch by name

Example

curl
curl https://api.hookbase.app/api/schemas \
  -H "Authorization: Bearer whr_your_api_key"

Response

{
  "data": [
    {
      "id": "sch_abc123",
      "name": "GitHub Push Event",
      "version": 1,
      "routeCount": 2,
      "createdAt": "2024-01-01T00:00:00Z"
    }
  ],
  "pagination": {
    "total": 3,
    "page": 1,
    "pageSize": 20
  }
}

Create Schema

POST /api/schemas

Request Body

FieldTypeRequiredDescription
namestringYesDisplay name
schemaobjectYesJSON Schema object (draft-07)
descriptionstringNoOptional description

Example

curl
curl -X POST https://api.hookbase.app/api/schemas \
  -H "Authorization: Bearer whr_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Stripe Payment Event",
    "description": "Validates Stripe payment_intent webhooks",
    "schema": {
      "type": "object",
      "required": ["type", "data"],
      "properties": {
        "type": {
          "type": "string",
          "pattern": "^payment_intent\\."
        },
        "data": {
          "type": "object",
          "required": ["object"],
          "properties": {
            "object": {
              "type": "object",
              "required": ["id", "amount", "currency"],
              "properties": {
                "id": { "type": "string" },
                "amount": { "type": "integer", "minimum": 0 },
                "currency": { "type": "string", "minLength": 3, "maxLength": 3 }
              }
            }
          }
        }
      }
    }
  }'

Response

{
  "id": "sch_new123",
  "name": "Stripe Payment Event",
  "description": "Validates Stripe payment_intent webhooks",
  "schema": { ... },
  "version": 1,
  "routeCount": 0,
  "createdAt": "2024-01-15T10:30:00Z",
  "updatedAt": "2024-01-15T10:30:00Z"
}

Get Schema

GET /api/schemas/{id}

Example

curl
curl https://api.hookbase.app/api/schemas/sch_abc123 \
  -H "Authorization: Bearer whr_your_api_key"

Response

Returns the full schema object.

Update Schema

PATCH /api/schemas/{id}

Request Body

All fields are optional. Only provided fields are updated.

FieldTypeDescription
namestringDisplay name
schemaobjectJSON Schema object
descriptionstringOptional description

Info

Updating the schema field automatically increments the version number.

Example

curl
curl -X PATCH https://api.hookbase.app/api/schemas/sch_abc123 \
  -H "Authorization: Bearer whr_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "schema": {
      "type": "object",
      "required": ["ref", "repository", "pusher", "commits"],
      "properties": {
        "ref": { "type": "string" },
        "commits": { "type": "array", "minItems": 1 }
      }
    }
  }'

Response

Returns the updated schema object with incremented version.

Delete Schema

DELETE /api/schemas/{id}

Warning

A schema cannot be deleted while it is assigned to active routes. Remove it from all routes first.

Example

curl
curl -X DELETE https://api.hookbase.app/api/schemas/sch_abc123 \
  -H "Authorization: Bearer whr_your_api_key"

Response

204 No Content

Schema Validation Behavior

When a schema is attached to a route:

  1. Incoming event payloads are validated against the JSON Schema
  2. Valid payloads proceed through the route normally
  3. Invalid payloads result in deliveries with status schema_failed
  4. Validation errors are recorded on the delivery for debugging

Viewing Validation Errors

Check the delivery detail for schema validation errors:

{
  "id": "dlv_abc123",
  "status": "schema_failed",
  "error": "Schema validation failed: /data/object/amount must be integer, got string",
  "schemaId": "sch_abc123",
  "schemaVersion": 1
}

Error Responses

400 Bad Request

Invalid JSON Schema:

{
  "error": "Bad Request",
  "message": "Invalid JSON Schema: 'type' must be a valid JSON Schema type",
  "code": "INVALID_SCHEMA"
}

409 Conflict

Schema in use:

{
  "error": "Conflict",
  "message": "Schema is assigned to 2 active routes",
  "code": "RESOURCE_IN_USE"
}