Skip to content

Define metric

POST
/v1/actions/hospitality.action.define_metric/apply
curl --request POST \
--url https://api.aerandil.com/v1/actions/hospitality.action.define_metric/apply \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "branch": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "params": { "description": "example", "display_name": "example", "formula_expression": "example", "grain": "property_day", "name": "example", "owner": "example", "referenced_fields": [ "example" ], "referenced_object_types": [ "example" ], "unit": "money" }, "return_modified": false }'

Create version 1 of a governed metric definition in draft. name is the stable snake_case identifier (matching a conformed registry metric when one exists — certifying that executable definition — or naming operator vocabulary the platform does not yet compute). The handler validates every referenced object type and field against the Registry; a definition cannot reference a field that doesn’t exist. One live row per name — evolving an existing definition is revise_metric. Emits metric.defined.

Effects: create hospitality.metric_definition.

Media typeapplication/json
object
branch

Apply against an open branch’s overlay view instead of the canonical (main) plane. The action’s writes land in the branch’s copy-on-first-write overlay, its events in the branch’s own stream, and the invocation is journaled for merge-by-replay. Branch writes are action-only, so this is the write-side entry point to a branch (POST /v1/branches forks one).

string format: uuid
params
required
object
description
required
Disambiguating prose — the definition operators sign off on
string
display_name
required
Display name
string
formula_expression
required
Canonical formula expression (governed prose, not executed)
string
grain
required
Organisational-unit × period grain
string
Allowed values: property_day property_month venue_day venue_month outlet_day brand_month portfolio_month tenant_month
name
required
Stable metric name (snake_case)
string
owner
required
Accountable team / principal for the definition
string
referenced_fields
required
Registered `<object_type>.<property>` fields the formula reads
Array<string>
referenced_object_types
required
Registered object-type names the formula reads
Array<string>
unit
required
Unit the metric's value carries
string
Allowed values: money ratio percent count hours native_unit
return_modified

When true, the response carries modified_objects and modified_links projections — the engine reads the event log inside the same transaction so the projection observes the handler’s own writes.

boolean

Action applied. modified_objects and modified_links populated when return_modified: true was supplied.

Media typeapplication/json
ApplyActionResponse

Envelope returned by the Aerandil action engine. correlation_id ties every event emitted by this invocation; modified_objects and modified_links project the events the handler emitted (per the action’s declared effects); warnings carries any non-blocking soft-validator observations.

object
correlation_id
required

Per-invocation correlation id; matches events.correlation_id for every event this action appended.

string format: uuid
modified_links
required

Links established or removed by this invocation. Empty when the caller did not request return_modified.

Array<object>
object
from_id
required
string format: uuid
from_type
required
string
kind
required
Allowed values: linked unlinked properties_updated end_dated
link_type
required
string
to_id
required
string format: uuid
to_type
required
string
modified_objects
required

Objects created, modified, or soft-deleted by this invocation. Empty when the caller did not request return_modified.

Array<object>
object
id
required
string format: uuid
kind
required
Allowed values: created
object_type
required
Allowed values: hospitality.metric_definition
warnings

Non-blocking soft-validator observations emitted during this invocation (e.g. comp-authority over-limit, recipe pour-cost over sell-price). Absent when no warnings were emitted.

Array<object>
object
message
required

Human-readable summary, suitable for logging or operator-UI surfacing.

string
object_type
required

Object type the warning was raised against.

string
property

Property the warning anchors to, when a single field is the locus. Absent for multi-field rules.

string
rule
required

Stable kebab-case rule identifier (e.g. comp-authority-over-limit).

string
Example
{
"modified_links": [
{
"kind": "linked"
}
],
"modified_objects": [
{
"kind": "created",
"object_type": "hospitality.metric_definition"
}
]
}

Conflict — concurrent modification or unique constraint violation.

Validation error — parameter validation or business-rule violation.