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

List

Get batched usage data
client.V1.Usage.List(ctx, params) (*DataarrayNextPagestringV1UsageListResponse, error)
post/v1/usage

Fetch aggregated usage data for multiple customers and billable-metrics, broken into intervals of the specified length.

Parameters
paramsEndingBeforefieldStartingOnfieldWindowSizefieldNextPagefieldBillableMetricsfieldCustomerIDsfieldV1UsageListParams
Hide ParametersShow Parameters
EndingBeforefield
param.Field[Time]

Body param:

formatdate-time
StartingOnfield
param.Field[Time]

Body param:

formatdate-time
WindowSizefield

Body param: A window_size of "day" or "hour" will return the usage for the specified period segmented into daily or hourly aggregates. A window_size of "none" will return a single usage aggregate for the entirety of the specified period.

Hide ParametersShow Parameters
V1UsageListParamsWindowSizeHourconst
"HOUR"
V1UsageListParamsWindowSizeDayconst
"DAY"
V1UsageListParamsWindowSizeNoneconst
"NONE"
NextPagefield
optional
param.Field[string]

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

BillableMetricsfield
optional

Body param: A list of billable metrics to fetch usage for. If absent, all billable metrics will be returned.

Hide ParametersShow Parameters
IDstring
formatuuid
GroupByKeystringValuesarrayV1UsageListParamsBillableMetricsGroupBy
optional
Hide ParametersShow Parameters
Keystring

The name of the group_by key to use

Valuesarray
optional
[]string

Values of the group_by key to return in the query. If this field is omitted, all available values will be returned, up to a maximum of 200.

CustomerIDsfield
optional
param.Field[[]string]

Body param: A list of Metronome customer IDs to fetch usage for. If absent, usage for all customers will be returned.

Returns
V1UsageListResponsestruct
Hide ParametersShow Parameters
Hide ParametersShow Parameters
BillableMetricIDstring
formatuuid
BillableMetricNamestring
CustomerIDstring
formatuuid
EndTimestampTime
formatdate-time
StartTimestampTime
formatdate-time
Valuefloat64
Groupsmap
optional
map[string, float64]

Values will be either a number or null. Null indicates that there were no matches for the group_by value.

NextPagestring
package main

import (
  "context"
  "fmt"
  "time"

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

func main() {
  client := metronome.NewClient(
    option.WithBearerToken("My Bearer Token"),
  )
  usages, err := client.V1.Usage.List(context.TODO(), metronome.V1UsageListParams{
    EndingBefore: metronome.F(time.Now()),
    StartingOn: metronome.F(time.Now()),
    WindowSize: metronome.F(metronome.V1UsageListParamsWindowSize("day")),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", usages.Data)
}
200 Example
{
  "data": [
    {
      "billable_metric_id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
      "billable_metric_name": "billable_metric_name",
      "customer_id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
      "end_timestamp": "2019-12-27T18:11:19.117Z",
      "start_timestamp": "2019-12-27T18:11:19.117Z",
      "value": 0,
      "groups": {
        "foo": 0
      }
    }
  ],
  "next_page": "next_page"
}