ContractsCreate or replace one event's contract

Create or replace one event's contract

Upserts the contract for one event name. Replaces the property set: a key omitted from properties stops being checked. Merge is not offered because it has no way to express "stop requiring this field".

A bare type string is shorthand for { "type": <t>, "required": true }. Required is the default because a contract whose every property is optional cannot fail, and is indistinguishable from no contract at all.

min_daily_events follows the same replace rule: omit it and the volume check is off.

Agency key (ak_) required.

curl -X PUT "https://mythic-analytics.gulp.workers.dev/client/v1/contracts?location_id=example_string" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
  "event": "order_completed",
  "properties": {
    "value": "number",
    "currency": "string",
    "coupon_code": {
      "type": "string",
      "required": false
    }
  },
  "note": "Checkout v3 — value is gross, pre-refund",
  "min_daily_events": 100
}'
{
  "success": true,
  "data": {
    "event": "order_completed",
    "properties": {},
    "note": "example_string",
    "min_daily_events": 100,
    "created_at": "2024-12-25T10:00:00Z",
    "updated_at": "2024-12-25T10:00:00Z"
  }
}
PUT
/client/v1/contracts
PUT
Base URLstring

Target server for requests. Edit to use your own host.

Bearer Token
Bearer Tokenstring
Required

Agency key (ak_) or location secret key (sk_). Scoped keys (mcp_) are accepted too and need contracts:read or contracts:write. See Using an mcp_ key over HTTP.

Agency key (ak_) or location secret key (sk_). Scoped keys (mcp_) are accepted too and need contracts:read or contracts:write. See Using an mcp_ key over HTTP.
query
location_idstring

Location to scope to. Required for ak_ keys (or send the X-Location-Id header); ignored for sk_.

Content-Typestring
Required

The media type of the request body

Options: application/json
eventstring
Required

Event name the contract applies to.

Max length: 200
propertiesobject
Required

Map of property key to type. Value is either a type string (required) or { type, required }. Keys cannot be empty.

notestring

Free text — where the contract came from. Echoed back on read.

Max length: 500
min_daily_eventsinteger

Declared minimum events per day for this event name. Below it, the report adds a low_volume violation. null or omitted means the check is off. Compared against the unsampled reference count and only over an exact whole-day window (pass both date_from and date_to) — a volume threshold checked against a sampled scan, or against the fuzzy default window, fires on healthy traffic. When either is missing the check is skipped and says so under the event's warnings, never as a violation. This is what makes alerting possible without a volume-baseline engine: the threshold is declared rather than inferred.

Min: 1
Request Preview
Response

Response will appear here after sending the request

Authentication

header
Authorizationstring
Required

Bearer token. Agency key (ak_) or location secret key (sk_). Scoped keys (mcp_) are accepted too and need contracts:read or contracts:write. See Using an mcp_ key over HTTP.

Query Parameters

location_idstring

Location to scope to. Required for ak_ keys (or send the X-Location-Id header); ignored for sk_.

Body

application/json
eventstring
Required

Event name the contract applies to.

Example:
order_completed
propertiesobject
Required

Map of property key to type. Value is either a type string (required) or \\{ type, required \\}. Keys cannot be empty.

Example:
{"value":"number","currency":"string","coupon_code":{"type":"string","required":false}}
notestring

Free text — where the contract came from. Echoed back on read.

Example:
Checkout v3 — value is gross, pre-refund
min_daily_eventsinteger

Declared minimum events per day for this event name. Below it, the report adds a low_volume violation. null or omitted means the check is off.

Compared against the unsampled reference count and only over an exact whole-day window (pass both date_from and date_to) — a volume threshold checked against a sampled scan, or against the fuzzy default window, fires on healthy traffic. When either is missing the check is skipped and says so under the event's warnings, never as a violation.

This is what makes alerting possible without a volume-baseline engine: the threshold is declared rather than inferred.

Example:
100

Responses

successboolean
dataobject