Create a metric
Creates an event-backed metric. Pass the query as the DSL string (query) or the typed IR (query_ir) — exactly one. event_name must equal the event the query…
Creates an event-backed metric. Pass the query as the DSL string (query) or
the typed IR (query_ir) — exactly one. event_name must equal the event the
query references.
Returns 409 if a metric with the same name already exists, and 422 if the
query is invalid or references an unregistered event / label.
- Track an event —
count_users(<event>)for unique-user counts. - Sum a value —
sum(<event>, <label>)for revenue / quantity metrics. - Experiment success metric — create the metric, then attach its id to an experiment.
Authorization
bearerSdkKey Pass an admin SDK key as Authorization: Bearer sdk_admin_…. Mint via POST /api/admin/keys with type: "admin".
In: header
Header Parameters
Project the request operates on. Optional — defaults to the project the SDK key belongs to; pass it only to scope a multi-project key (the generated client sets it once from its configuration, so per-call callers never thread it).
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://shipeasy.ai/api/admin/metrics" \ -H "Content-Type: application/json" \ -d '{ "name": "checkouts", "event_name": "checkout_completed", "query": "count_users(checkout_completed)" }'{
"id": "met_01j7w8a1b2c3d4e5f6g7h8i9j0",
"name": "checkouts"
}{
"error": "Malformed request (bad JSON, missing project scope).",
"code": "BAD_REQUEST"
}{
"error": "Missing or invalid admin SDK key.",
"code": "UNAUTHORIZED"
}{
"error": "Key is valid but not allowed to act on this project.",
"code": "FORBIDDEN"
}{
"error": "The resource does not exist or is not visible to the caller.",
"code": "NOT_FOUND"
}{
"error": "A resource with this name already exists in the project.",
"code": "ALREADY_EXISTS"
}{
"error": "The request body failed structural (schema) validation.",
"code": "VALIDATION"
}