Metrics

Create Metric

Create a metric definition. Simple metrics require eventName, aggregationType, and valueType. Indexed/complex metrics require a SELECT-only sqlDefinition over the filtered_events CTE (safe functions only).

POST
/metrics

Authorization

bearerAuth
AuthorizationBearer <token>

Use your secret API key as the bearer token

In: header

Request Body

application/json

name*string
Lengthlength <= 100
description?string
queryType*string

Must be simple for this shape.

Value in"simple"
aggregationType*string
Value in"COUNT" | "SUM" | "MAX" | "MIN" | "AVG" | "UNIQUE_COUNT"
eventName*string
valueType*string
Value in"NUMERIC" | "STRING"
sqlDefinition?string|null

Not used for simple metrics (must be omitted).

Response Body

application/json

application/json

application/json

curl -X POST "https://api.getlumen.dev/v1/metrics" \  -H "Content-Type: application/json" \  -d '{    "name": "API Calls",    "description": "Count of successful API calls",    "queryType": "simple",    "aggregationType": "COUNT",    "eventName": "api-call",    "valueType": "NUMERIC"  }'
{
  "id": "met_DQ6f7a8b9c0d1e2f3g4h5i",
  "merchantId": "mer_1234567890abcdefghij",
  "name": "API Calls",
  "description": "Count of successful API calls",
  "queryType": "simple",
  "aggregationType": "COUNT",
  "eventName": "api-call",
  "valueType": "NUMERIC",
  "sqlDefinition": null,
  "createdAt": "2025-02-20T17:00:00.000Z",
  "updatedAt": "2025-02-20T17:00:00.000Z"
}
{
  "error": "Invalid metric definition. Simple metrics require aggregationType, eventName, valueType and no sqlDefinition. Indexed/Complex metrics require a valid SELECT-only sqlDefinition and no simple metric fields."
}
{
  "error": "Internal server error"
}