Skip to main content

Register an Event Schema

Register an Event Schema​

Registration stores one schema version for one event type inside one tenant. It has two prerequisites: a privacy configuration that classifies the schema's fields, and a credential allowed to write schemas for that tenant. Both are tenant-scoped, so a tenant administrator can never register for another company.

Choose a surface​

SurfaceRouteAuthority
Machine or automationPOST /api/v1/schemasA tenant credential with the schemas.write scope. The producer-provisioning schemas scope template resolves to events.write + schemas.write.
Operator or personPOST /api/v1/admin/schema/{tenantSlug}/{eventType}/registertenant_admin for its own tenant, or system_admin for any tenant it names.
  • Both surfaces write into the tenant the credential belongs to. On the admin surface a tenant administrator naming a different company is answered 404; only platform authority may name another tenant.

  • In the browser, Schemas (/schemas) registers through the registry route with your own session, while Admin → Schema Tools (/admin?tab=schema-tools) uses the admin route. In custdctl:

    custdctl schema register --profile prod --tenant-slug acme \
    --event-type page-view --version 1.0.0 --schema-file schema.json --enabled

    custdctl schema register defaults to --enabled=false, so pass --enabled for a new event type (see "Register a new event type enabled" below).

Configure privacy first​

Every registration runs the tenant's privacy check before anything is stored, whatever enabled or isActive you send. POST /api/v1/schemas/validate and /dry-run run the same check. Until the tenant has an enabled privacy configuration whose apply mode is at_ingestion, the call is refused with HTTP 400:

enabled ingestion privacy configuration is required: privacy config not found

Every tenant starts without one. Create it through the supported API as the tenant's administrator (or a system administrator naming the tenant). No SQL is needed:

curl -sf -X PUT "$ADMIN_API_URL/api/v1/admin/privacy/rules" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"companySlug": "acme",
"applyMode": "at_ingestion",
"enabled": true,
"rules": [
{"fieldPath": "payload.url", "action": "strip_query", "enabled": true},
{"fieldPath": "payload.path", "action": "keep", "enabled": true}
]
}'

custdctl privacy rules set --profile prod --company acme --file privacy.json writes the same configuration, and custdctl privacy rules get --profile prod --company acme reads it back.

Each rule needs its own "enabled": true. The endpoint returns 200 whether or not you set it; a rule stored without it is disabled and silently ignored by the schema check.

Fields must be classified​

The check walks the schema's own fields and matches each one against a privacy rule whose path starts at payload., because the schema describes the event payload:

  • A schema field with no enabled rule is refused: schema field "payload.path" is not classified by privacy rules. Add a rule for that exact path.
  • A field whose rule action is remove is refused: schema field "payload.url" is forbidden by privacy rules.
  • Every object in the schema must set "additionalProperties": false, or the check refuses it: object "payload" permits unclassified additional fields.

Validate, infer and dry-run​

Validate compiles the schema and its examples. Expect valid: true and schemaValid: true:

curl -sf -X POST "$API_URL/api/v1/schemas/validate" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"slug": "page-view",
"name": "Page View",
"version": "1.0.0",
"jsonSchema": "{\"type\":\"object\",\"additionalProperties\":false,\"properties\":{\"url\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"}}}",
"examples": [{"url": "https://shop.example.test/a?utm_source=x", "path": "/a"}]
}'
  • POST /api/v1/schemas/infer with {"samples": [...]} returns a candidateSchema to review, not to register unreviewed.
  • POST /api/v1/schemas/dry-run takes the same body as validate and reports wouldCreateEventType, wouldCreateVersion and conflicts before you write anything.
  • Admin equivalents are POST /api/v1/admin/schema/validate and POST /api/v1/admin/schema/{tenantSlug}/{eventType}/dry-run, with tenantSlug, eventTypeSlug, schemaJson and dialect (jsonschema) in the body.

Register the version​

Machine surface, using a tenant credential:

curl -sf -X POST "$API_URL/api/v1/schemas" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"slug": "page-view",
"name": "Page View",
"version": "1.0.0",
"jsonSchema": "{\"type\":\"object\",\"additionalProperties\":false,\"properties\":{\"url\":{\"type\":\"string\"},\"path\":{\"type\":\"string\"}}}",
"enabled": true,
"isActive": true
}'

Admin surface, using an administrator token. This route also requires a checksum: the lowercase hex sha256 of the exact schemaJson string, computed by the caller. A missing or malformed checksum is refused with schema action: checksum must be 64 lowercase hex characters (sha256).

SCHEMA='{"type":"object","additionalProperties":false,"properties":{"url":{"type":"string"},"path":{"type":"string"}}}'
CHECKSUM="$(printf '%s' "$SCHEMA" | shasum -a 256 | cut -d' ' -f1)"

curl -sf -X POST "$ADMIN_API_URL/api/v1/admin/schema/acme/page-view/register" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"tenantSlug\": \"acme\",
\"eventTypeSlug\": \"page-view\",
\"version\": \"1.0.0\",
\"schemaJson\": $(printf '%s' "$SCHEMA" | jq -Rs .),
\"dialect\": \"jsonschema\",
\"checksum\": \"$CHECKSUM\",
\"enabled\": true
}"

The machine route answers 201; the admin route answers 204. The admin body's tenantSlug and eventTypeSlug must match the URL, or the call is answered 404. Both examples use curl -f, which hides the error body; drop -f when you need to read the 400 detail.

Once active, events with eventTypeSlug: "page-view" and schemaVersion: "1.0.0" validate against that schema.

Register enabled, or enable later. Pass --enabled to register and activate in one step through the admin surface. Without it, registration stores an inactive version; custdctl schema enable restores and activates that version and its tenant-owned event type. Enable repeats the privacy check. If activation fails, the command fails and can be retried safely. A disabled tenant type retains its identity and versions; registering another version reuses that row.

Verify​

  • Machine surface: GET /api/v1/schemas/page-view/versions lists the stored versions for your tenant.
  • Operator surface: GET /api/v1/admin/schema/audit?tenantSlug=acme, or custdctl schema audit --profile prod --tenant-slug acme.
  • Send one matching event with eventTypeSlug: "page-view" and schemaVersion: "1.0.0", and require success: true plus an event UUID in the response before sending volume. See Send Events and Ready Data.

Version conflicts​

Dry-run reports an existing version as a conflict. Registering a version that already exists with identical content is idempotent; registering it with different content is refused as a conflict. Inspect the existing definition and create a new version instead; do not silently change the meaning of a version other events already reference.