Class: MetronomeSDK::Resources::V1::BillableMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/metronome_sdk/resources/v1/billable_metrics.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ BillableMetrics

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BillableMetrics.

Parameters:



171
172
173
# File 'lib/metronome_sdk/resources/v1/billable_metrics.rb', line 171

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(id: , request_options: {}) ⇒ MetronomeSDK::Models::V1::BillableMetricArchiveResponse

Use this endpoint to retire billable metrics that are no longer used. After a billable metric is archived, that billable metric can no longer be used in any new Products to define how that product should be metered. If you archive a billable metric that is already associated with a Product, the Product will continue to function as usual, metering based on the definition of the archived billable metric.

Archived billable metrics will be returned on the ‘getBillableMetric` and `listBillableMetrics` endpoints with a populated `archived_at` field.

Parameters:

Returns:

See Also:



157
158
159
160
161
162
163
164
165
166
# File 'lib/metronome_sdk/resources/v1/billable_metrics.rb', line 157

def archive(params)
  parsed, options = MetronomeSDK::V1::BillableMetricArchiveParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/billable-metrics/archive",
    body: parsed,
    model: MetronomeSDK::Models::V1::BillableMetricArchiveResponse,
    options: options
  )
end

#create(name: , aggregation_key: nil, aggregation_type: nil, custom_fields: nil, event_type_filter: nil, group_keys: nil, property_filters: nil, sql: nil, request_options: {}) ⇒ MetronomeSDK::Models::V1::BillableMetricCreateResponse

Some parameter documentations has been truncated, see Models::V1::BillableMetricCreateParams for more details.

Create billable metrics programmatically with this endpoint—an essential step in configuring your pricing and packaging in Metronome.

A billable metric is a customizable query that filters and aggregates events from your event stream. These metrics are continuously tracked as usage data enters Metronome through the ingestion pipeline. The ingestion process transforms raw usage data into actionable pricing metrics, enabling accurate metering and billing for your products.

### Use this endpoint to:

  • Create individual or multiple billable metrics as part of a setup workflow.

  • Automate the entire pricing configuration process, from metric creation to customer contract setup.

  • Define metrics using either standard filtering/aggregation or a custom SQL query.

### Key response fields:

  • The ID of the billable metric that was created

  • The created billable metric will be available to be used in Products, usage endpoints, and alerts.

### Usage guidelines:

  • Metrics defined using standard filtering and aggregation are Streaming billable metrics, which have been optimized for ultra low latency and high throughput workflows.

  • Use SQL billable metrics if you require more flexible aggregation options.

Parameters:

  • name (String)

    The display name of the billable metric.

  • aggregation_key (String)

    Specifies the type of aggregation performed on matching events. Required if ‘sql

  • aggregation_type (Symbol, MetronomeSDK::Models::V1::BillableMetricCreateParams::AggregationType)

    Specifies the type of aggregation performed on matching events.

  • custom_fields (Hash{Symbol=>String})

    Custom fields to attach to the billable metric.

  • event_type_filter (MetronomeSDK::Models::EventTypeFilter)

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

  • group_keys (Array<Array<String>>)

    Property names that are used to group usage costs on an invoice. Each entry repr

  • property_filters (Array<MetronomeSDK::Models::PropertyFilter>)

    A list of filters to match events to this billable metric. Each filter defines a

  • sql (String)

    The SQL query associated with the billable metric. This field is mutually exclus

  • request_options (MetronomeSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



63
64
65
66
67
68
69
70
71
72
# File 'lib/metronome_sdk/resources/v1/billable_metrics.rb', line 63

def create(params)
  parsed, options = MetronomeSDK::V1::BillableMetricCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/billable-metrics/create",
    body: parsed,
    model: MetronomeSDK::Models::V1::BillableMetricCreateResponse,
    options: options
  )
end

#list(include_archived: nil, limit: nil, next_page: nil, request_options: {}) ⇒ MetronomeSDK::Internal::CursorPage<MetronomeSDK::Models::V1::BillableMetricListResponse>

Retrieves all billable metrics with their complete configurations. Use this for programmatic discovery and management of billable metrics, such as associating metrics to products and auditing for orphaned or archived metrics. Important: Archived metrics are excluded by default; use ‘include_archived`=`true` parameter to include them.

Parameters:

  • include_archived (Boolean)

    If true, the list of returned metrics will include archived metrics

  • limit (Integer)

    Max number of results that should be returned

  • next_page (String)

    Cursor that indicates where the next page of results should start.

  • request_options (MetronomeSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/metronome_sdk/resources/v1/billable_metrics.rb', line 127

def list(params = {})
  parsed, options = MetronomeSDK::V1::BillableMetricListParams.dump_request(params)
  @client.request(
    method: :get,
    path: "v1/billable-metrics",
    query: parsed,
    page: MetronomeSDK::Internal::CursorPage,
    model: MetronomeSDK::Models::V1::BillableMetricListResponse,
    options: options
  )
end

#retrieve(billable_metric_id: , request_options: {}) ⇒ MetronomeSDK::Models::V1::BillableMetricRetrieveResponse

Retrieves the complete configuration for a specific billable metric by its ID. Use this to review billable metric setup before associating it with products. Returns the metric’s ‘name`, `event_type_filter`, `property_filters`, `aggregation_type`, `aggregation_key`, `group_keys`, `custom fields`, and `SQL query` (if it’s a SQL billable metric).

Important:

  • Archived billable metrics will include an ‘archived_at` timestamp; they no longer process new usage events but remain accessible for historical reference.

Parameters:

Returns:

See Also:



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/metronome_sdk/resources/v1/billable_metrics.rb', line 94

def retrieve(params)
  parsed, options = MetronomeSDK::V1::BillableMetricRetrieveParams.dump_request(params)
  billable_metric_id =
    parsed.delete(:billable_metric_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["v1/billable-metrics/%1$s", billable_metric_id],
    model: MetronomeSDK::Models::V1::BillableMetricRetrieveResponse,
    options: options
  )
end