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

Create

Create a billable metric
client.V1.BillableMetrics.New(ctx, body) (*DataIDV1BillableMetricNewResponse, error)
post/v1/billable-metrics/create

Creates a new Billable Metric.

Parameters
bodyNamefieldAggregationKeyfieldAggregationTypefieldCustomFieldsfieldEventTypeFilterfieldGroupKeysfieldPropertyFiltersfieldSqlfieldV1BillableMetricNewParams
Hide ParametersShow Parameters
Namefield
param.Field[string]

The display name of the billable metric.

AggregationKeyfield
optional
param.Field[string]

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

AggregationTypefield
optional

Specifies the type of aggregation performed on matching events.

Hide ParametersShow Parameters
V1BillableMetricNewParamsAggregationTypeCountconst
"COUNT"
V1BillableMetricNewParamsAggregationTypeLatestconst
"LATEST"
V1BillableMetricNewParamsAggregationTypeMaxconst
"MAX"
V1BillableMetricNewParamsAggregationTypeSumconst
"SUM"
V1BillableMetricNewParamsAggregationTypeUniqueconst
"UNIQUE"
CustomFieldsfield
optional
param.Field[map[string, string]]

Custom fields to attach to the billable metric.

EventTypeFilterfield
optional
param.Field[InValuesarrayNotInValuesarrayEventTypeFilter]

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

GroupKeysfield
optional
param.Field[[][]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.

PropertyFiltersfield
optional
param.Field[[]NamestringExistsboolInValuesarrayNotInValuesarrayPropertyFilter]

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.

InValuesarray
optional
[]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.

NotInValuesarray
optional
[]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.

Sqlfield
optional
param.Field[string]

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
V1BillableMetricNewResponsestruct
Hide ParametersShow Parameters
DataIDstringID
package main

import (
  "context"
  "fmt"

  "github.com/Metronome-Industries/metronome-go"
  "github.com/Metronome-Industries/metronome-go/option"
  "github.com/Metronome-Industries/metronome-go/shared"
)

func main() {
  client := metronome.NewClient(
    option.WithBearerToken("My Bearer Token"),
  )
  billableMetric, err := client.V1.BillableMetrics.New(context.TODO(), metronome.V1BillableMetricNewParams{
    Name: metronome.F("CPU Hours"),
    AggregationKey: metronome.F("cpu_hours"),
    AggregationType: metronome.F(metronome.V1BillableMetricNewParamsAggregationTypeSum),
    EventTypeFilter: metronome.F(shared.EventTypeFilterParam{
      InValues: metronome.F([]string{"cpu_usage"}),
    }),
    GroupKeys: metronome.F([][]string{[]string{"region"}, []string{"machine_type"}}),
    PropertyFilters: metronome.F([]shared.PropertyFilterParam{shared.PropertyFilterParam{
      Name: metronome.F("cpu_hours"),
      Exists: metronome.F(true),
    }, shared.PropertyFilterParam{
      Name: metronome.F("region"),
      Exists: metronome.F(true),
      InValues: metronome.F([]string{"EU", "NA"}),
    }, shared.PropertyFilterParam{
      Name: metronome.F("machine_type"),
      Exists: metronome.F(true),
      InValues: metronome.F([]string{"slow", "fast"}),
    }}),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", billableMetric.Data)
}
200 Example
{
  "data": {
    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
  }
}