Pular para o conteúdo principal

Create Metric

POST 

/api/v2/org/:org_id/workspace/:workspace_id/metrics

Create a new workspace metric.

Creates a CloudEvents-compatible metric record for the specified workspace. If event_id is not provided, a unique UUID7 will be generated automatically. If time is not provided, the current UTC timestamp will be used. If subject is not provided, the authenticated user's member_id will be used.

Args:

org_id (str): Path parameter - Organization ID that owns the workspace workspace_id (str): Path parameter - Target workspace ID for the metric metric_data (MetricCreateRequest): Request body containing:

  • specversion (str): CloudEvents spec version (defaults to "1.0")
  • type (str): Metric type identifier (e.g., "auth.user.login")
  • event_id (str, optional): Unique event identifier (auto-generated if not provided)
  • time (datetime, optional): Event timestamp (current UTC time if not provided)
  • source (str): Event source identifier
  • subject (str, optional): Event subject (user member_id if not provided)
  • data (dict): Metric payload data

Returns

MetricView: The created metric with all computed fields populated

Details

  • Duplicate metrics are prevented by the combination of (workspace_id, source, event_id)
  • The 'time' field in the request body refers to the event time, not creation time
  • Auto-generated event_id uses UUID7 which includes timestamp information
  • Subject defaults to the authenticated user's member_id, not their user_id

Permissions:

  • Scope: workspace_metrics:write
  • Allowed Roles:
    • superadmin: ✓
    • admin: ✓
    • controller: ✓
    • curator: ✓
    • basic: ✓

Request

Responses

Successful Response