# Customers ## Create `v1.customers.create(**kwargs) -> CustomerCreateResponse` **post** `/v1/customers` Create a new customer ### Parameters - **name:** `String` This will be truncated to 160 characters if the provided name is longer. - **billing\_config:** `{ billing_provider_customer_id, billing_provider_type, aws_is_subscription_product, 3 more}` - **billing\_provider\_customer\_id:** `String` - **billing\_provider\_type:** `:aws_marketplace | :stripe | :netsuite | 5 more` - `:aws_marketplace` - `:stripe` - `:netsuite` - `:custom` - `:azure_marketplace` - `:quickbooks_online` - `:workday` - `:gcp_marketplace` - **aws\_is\_subscription\_product:** `bool` True if the aws_product_code is a SAAS subscription product, false otherwise. - **aws\_product\_code:** `String` - **aws\_region:** `:"af-south-1" | :"ap-east-1" | :"ap-northeast-1" | 22 more` - `:"af-south-1"` - `:"ap-east-1"` - `:"ap-northeast-1"` - `:"ap-northeast-2"` - `:"ap-northeast-3"` - `:"ap-south-1"` - `:"ap-southeast-1"` - `:"ap-southeast-2"` - `:"ca-central-1"` - `:"cn-north-1"` - `:"cn-northwest-1"` - `:"eu-central-1"` - `:"eu-north-1"` - `:"eu-south-1"` - `:"eu-west-1"` - `:"eu-west-2"` - `:"eu-west-3"` - `:"me-south-1"` - `:"sa-east-1"` - `:"us-east-1"` - `:"us-east-2"` - `:"us-gov-east-1"` - `:"us-gov-west-1"` - `:"us-west-1"` - `:"us-west-2"` - **stripe\_collection\_method:** `:charge_automatically | :send_invoice` - `:charge_automatically` - `:send_invoice` - **custom\_fields:** `Hash[Symbol, String]` - **customer\_billing\_provider\_configurations:** `Array[{ billing_provider, configuration, delivery_method, delivery_method_id}]` - **billing\_provider:** `:aws_marketplace | :azure_marketplace | :gcp_marketplace | 2 more` The billing provider set for this configuration. - `:aws_marketplace` - `:azure_marketplace` - `:gcp_marketplace` - `:stripe` - `:netsuite` - **configuration:** `Hash[Symbol, untyped]` Configuration for the billing provider. The structure of this object is specific to the billing provider and delivery provider combination. Defaults to an empty object, however, for most billing provider + delivery method combinations, it will not be a valid configuration. - **delivery\_method:** `:direct_to_billing_provider | :aws_sqs | :tackle | :aws_sns` The method to use for delivering invoices to this customer. If not provided, the `delivery_method_id` must be provided. - `:direct_to_billing_provider` - `:aws_sqs` - `:tackle` - `:aws_sns` - **delivery\_method\_id:** `String` ID of the delivery method to use for this customer. If not provided, the `delivery_method` must be provided. - **external\_id:** `String` (deprecated, use ingest_aliases instead) an alias that can be used to refer to this customer in usage events - **ingest\_aliases:** `Array[String]` Aliases that can be used to refer to this customer in usage events ### Returns - `class CustomerCreateResponse` - **data:** `Customer` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") customer = metronome.v1.customers.create(name: "Example, Inc.") puts(customer) ``` ## Retrieve `v1.customers.retrieve(**kwargs) -> CustomerRetrieveResponse` **get** `/v1/customers/{customer_id}` Get a customer by Metronome ID. ### Parameters - **customer\_id:** `String` ### Returns - `class CustomerRetrieveResponse` - **data:** `CustomerDetail` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") customer = metronome.v1.customers.retrieve(customer_id: "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc") puts(customer) ``` ## List `v1.customers.list(**kwargs) -> CursorPage` **get** `/v1/customers` List all customers. ### Parameters - **customer\_ids:** `Array[String]` Filter the customer list by customer_id. Up to 100 ids can be provided. - **ingest\_alias:** `String` Filter the customer list by ingest_alias - **limit:** `Integer` Max number of results that should be returned - **next\_page:** `String` Cursor that indicates where the next page of results should start. - **only\_archived:** `bool` Filter the customer list to only return archived customers. By default, only active customers are returned. - **salesforce\_account\_ids:** `Array[String]` Filter the customer list by salesforce_account_id. Up to 100 ids can be provided. ### Returns - `CustomerDetail` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") page = metronome.v1.customers.list puts(page) ``` ## Archive `v1.customers.archive(**kwargs) -> CustomerArchiveResponse` **post** `/v1/customers/archive` Archive a customer Note: any alerts associated with the customer will not be triggered. ### Parameters - **id:** `String` ### Returns - `class CustomerArchiveResponse` - **data:** `ID` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") response = metronome.v1.customers.archive(id: "8deed800-1b7a-495d-a207-6c52bac54dc9") puts(response) ``` ## List Billable Metrics `v1.customers.list_billable_metrics(**kwargs) -> CursorPage` **get** `/v1/customers/{customer_id}/billable-metrics` Get all billable metrics for a given customer. ### Parameters - **customer\_id:** `String` - **include\_archived:** `bool` 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. - **on\_current\_plan:** `bool` If true, the list of metrics will be filtered to just ones that are on the customer's current plan ### Returns - `class CustomerListBillableMetricsResponse` - **id:** `String` - **name:** `String` - **aggregate:** `String` (DEPRECATED) use aggregation_type instead - **aggregate\_keys:** `Array[String]` (DEPRECATED) use aggregation_key instead - **aggregation\_key:** `String` A key that specifies which property of the event is used to aggregate data. This key must be one of the property filter names and is not applicable when the aggregation type is 'count'. - **aggregation\_type:** `:COUNT | :LATEST | :MAX | 2 more` Specifies the type of aggregation performed on matching events. - `:COUNT` - `:LATEST` - `:MAX` - `:SUM` - `:UNIQUE` - **archived\_at:** `Time` RFC 3339 timestamp indicating when the billable metric was archived. If not provided, the billable metric is not archived. - **custom\_fields:** `Hash[Symbol, String]` - **event\_type\_filter:** `EventTypeFilter` An optional filtering rule to match the 'event_type' property of an event. - **filter:** `Hash[Symbol, untyped]` (DEPRECATED) use property_filters & event_type_filter instead - **group\_by:** `Array[String]` (DEPRECATED) use group_keys instead - **group\_keys:** `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\_filters:** `Array[PropertyFilter]` 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. - **name:** `String` The name of the event property. - **exists:** `bool` 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\_values:** `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\_values:** `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. - **sql:** `String` The SQL query associated with the billable metric ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") page = metronome.v1.customers.list_billable_metrics(customer_id: "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc") puts(page) ``` ## List Costs `v1.customers.list_costs(**kwargs) -> CursorPage` **get** `/v1/customers/{customer_id}/costs` Fetch daily pending costs for the specified customer, broken down by credit type and line items. Note: this is not supported for customers whose plan includes a UNIQUE-type billable metric. ### Parameters - **customer\_id:** `String` - **ending\_before:** `Time` RFC 3339 timestamp (exclusive) - **starting\_on:** `Time` RFC 3339 timestamp (inclusive) - **limit:** `Integer` Max number of results that should be returned - **next\_page:** `String` Cursor that indicates where the next page of results should start. ### Returns - `class CustomerListCostsResponse` - **credit\_types:** `Hash[Symbol, { cost, line_item_breakdown, name}]` - **cost:** `Float` - **line\_item\_breakdown:** `Array[{ cost, name, group_key, group_value}]` - **cost:** `Float` - **name:** `String` - **group\_key:** `String` - **group\_value:** `String` - **name:** `String` - **end\_timestamp:** `Time` - **start\_timestamp:** `Time` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") page = metronome.v1.customers.list_costs( customer_id: "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc", ending_before: "2019-12-27T18:11:19.117Z", starting_on: "2019-12-27T18:11:19.117Z" ) puts(page) ``` ## Preview Events `v1.customers.preview_events(**kwargs) -> CustomerPreviewEventsResponse` **post** `/v1/customers/{customer_id}/previewEvents` Preview how a set of events will affect a customer's invoice. Generates a draft invoice for a customer using their current contract configuration and the provided events. This is useful for testing how new events will affect the customer's invoice before they are actually processed. ### Parameters - **customer\_id:** `String` - **events:** `Array[{ event_type, customer_id, properties, 2 more}]` - **event\_type:** `String` - **customer\_id:** `String` This has no effect for preview events, but may be set for consistency with Event objects. They will be processed even if they do not match the customer's ID or ingest aliases. - **properties:** `Hash[Symbol, untyped]` - **timestamp:** `String` RFC 3339 formatted. If not provided, the current time will be used. - **transaction\_id:** `String` This has no effect for preview events, but may be set for consistency with Event objects. Duplicate transaction_ids are NOT filtered out, even within the same request. - **mode:** `:replace | :merge` If set to "replace", the preview will be generated as if those were the only events for the specified customer. If set to "merge", the events will be merged with any existing events for the specified customer. Defaults to "replace". - `:replace` - `:merge` - **skip\_zero\_qty\_line\_items:** `bool` If set, all zero quantity line items will be filtered out of the response. ### Returns - `class CustomerPreviewEventsResponse` - **data:** `Invoice` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") response = metronome.v1.customers.preview_events( customer_id: "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc", events: [{event_type: "heartbeat"}] ) puts(response) ``` ## Set Ingest Aliases `v1.customers.set_ingest_aliases(**kwargs) -> void` **post** `/v1/customers/{customer_id}/setIngestAliases` Sets the ingest aliases for a customer. Ingest aliases can be used in the `customer_id` field when sending usage events to Metronome. This call is idempotent. It fully replaces the set of ingest aliases for the given customer. ### Parameters - **customer\_id:** `String` - **ingest\_aliases:** `Array[String]` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") result = metronome.v1.customers.set_ingest_aliases( customer_id: "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc", ingest_aliases: ["team@example.com"] ) puts(result) ``` ## Set Name `v1.customers.set_name(**kwargs) -> CustomerSetNameResponse` **post** `/v1/customers/{customer_id}/setName` Updates the specified customer's name. ### Parameters - **customer\_id:** `String` - **name:** `String` The new name for the customer. This will be truncated to 160 characters if the provided name is longer. ### Returns - `class CustomerSetNameResponse` - **data:** `Customer` ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") response = metronome.v1.customers.set_name( customer_id: "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc", name: "Example, Inc." ) puts(response) ``` ## Update Config `v1.customers.update_config(**kwargs) -> void` **post** `/v1/customers/{customer_id}/updateConfig` Updates the specified customer's config. ### Parameters - **customer\_id:** `String` - **leave\_stripe\_invoices\_in\_draft:** `bool` Leave in draft or set to auto-advance on invoices sent to Stripe. Falls back to the client-level config if unset, which defaults to true if unset. - **salesforce\_account\_id:** `String` The Salesforce account ID for the customer ### Example ```ruby require "metronome_sdk" metronome = MetronomeSDK::Client.new(bearer_token: "My Bearer Token") result = metronome.v1.customers.update_config(customer_id: "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc") puts(result) ``` ## Domain Types ### Customer - `class Customer` - **id:** `String` the Metronome ID of the customer - **external\_id:** `String` (deprecated, use ingest_aliases instead) the first ID (Metronome or ingest alias) that can be used in usage events - **ingest\_aliases:** `Array[String]` aliases for this customer that can be used instead of the Metronome customer ID in usage events - **name:** `String` - **custom\_fields:** `Hash[Symbol, String]` ### Customer Detail - `class CustomerDetail` - **id:** `String` the Metronome ID of the customer - **created\_at:** `Time` RFC 3339 timestamp indicating when the customer was created. - **custom\_fields:** `Hash[Symbol, String]` - **customer\_config:** `{ salesforce_account_id}` - **salesforce\_account\_id:** `String` The Salesforce account ID for the customer - **external\_id:** `String` (deprecated, use ingest_aliases instead) the first ID (Metronome or ingest alias) that can be used in usage events - **ingest\_aliases:** `Array[String]` aliases for this customer that can be used instead of the Metronome customer ID in usage events - **name:** `String` - **archived\_at:** `Time` RFC 3339 timestamp indicating when the customer was archived. Null if the customer is active. - **current\_billable\_status:** `{ value, effective_at}` This field's availability is dependent on your client's configuration. - **value:** `:billable | :unbillable` - `:billable` - `:unbillable` - **effective\_at:** `Time`