Skip to content
  • Auto
  • Light
  • Dark
Talk to an expert

Create

Create a billable metric
v1.billable_metrics.create(**kwargs) -> dataIDBillableMetricCreateResponse
post/v1/billable-metrics/create

Creates a new Billable Metric.

Parameters
nameString

The display name of the billable metric.

aggregation_keyString
optional

Specifies the type of aggregation performed on matching events. Required if sql is not provided.

aggregation_typeunion
optional
:COUNT | :LATEST | :MAX | 2 more

Specifies the type of aggregation performed on matching events.

Hide ParametersShow Parameters
:COUNT
:LATEST
:MAX
:SUM
:UNIQUE
custom_fieldshash
optional
Hash[Symbol, String]

Custom fields to attach to the billable metric.

event_type_filterin_valuesarraynot_in_valuesarrayEventTypeFilter
optional

An optional filtering rule to match the 'event_type' property of an event.

group_keysarray
optional
Array[Array[String]]

Property names that are used to group usage costs on an invoice. Each entry represents a set of properties used to slice events into distinct buckets.

property_filtersarray
optional
Array[nameStringexistsboolin_valuesarraynot_in_valuesarrayPropertyFilter]

A list of filters to match events to this billable metric. Each filter defines a rule on an event property. All rules must pass for the event to match the billable metric.

Hide ParametersShow Parameters
nameString

The name of the event property.

existsbool
optional

Determines whether the property must exist in the event. If true, only events with this property will pass the filter. If false, only events without this property will pass the filter. If null or omitted, the existence of the property is optional.

in_valuesarray
optional
Array[String]

Specifies the allowed values for the property to match an event. An event will pass the filter only if its property value is included in this list. If undefined, all property values will pass the filter. Must be non-empty if present.

not_in_valuesarray
optional
Array[String]

Specifies the values that prevent an event from matching the filter. An event will not pass the filter if its property value is included in this list. If null or empty, all property values will pass the filter. Must be non-empty if present.

sqlString
optional

The SQL query associated with the billable metric. This field is mutually exclusive with aggregation_type, event_type_filter, property_filters, aggregation_key, and group_keys. If provided, these other fields must be omitted.

Returns
BillableMetricCreateResponseclass
Hide ParametersShow Parameters
dataidStringID
require "metronome_sdk"

metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token")

billable_metric = metronome.v1.billable_metrics.create(name: "CPU Hours")

puts(billable_metric)
200 Example
{
  "data": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
  }
}