billable_metrics

Evaluate an expression for a billable metric

Changed on

This endpoint evaluates an expression against a test event. Use it to check an expression before you set it on a billable metric.

post/billable_metrics/evaluate_expression

Request

Request body

expressionstring required

Expression used to calculate the event units. The expression is evaluated for each event and the result is then used to calculate the total aggregated units. Event values are read with event.code, event.timestamp and event.properties.<name>. Accepted functions are ceil, concat, floor, greatest, least and round as well as +, -, / and * operations. ceil, floor and round accept an optional second parameter to specify the number of decimals.

Example request

{
  "expression": "round((event.properties.ended_at - event.properties.started_at) * event.properties.units)",
  "event": {
    "code": "storage",
    "properties": {
      "gb": 10
    }
  }
}

Response

Billable metric expression evaluation result

Example response

{
  "expression_result": {
    "value": "2.0"
  }
}

Changes