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

List With Groups

Get usage data with paginated groupings
client.V1.Usage.ListWithGroups(ctx, params) (*CursorPage[EndingBeforeTimeGroupKeystringGroupValuestringStartingOnTimeValuefloat64V1UsageListWithGroupsResponse], error)
post/v1/usage/groups

Fetch aggregated usage data for the specified customer, billable-metric, and optional group, broken into intervals of the specified length.

Parameters
paramsBillableMetricIDfieldCustomerIDfieldWindowSizefieldLimitfieldNextPagefieldCurrentPeriodfieldEndingBeforefieldGroupByfieldStartingOnfieldV1UsageListWithGroupsParams
Hide ParametersShow Parameters
BillableMetricIDfield
param.Field[string]

Body param:

formatuuid
CustomerIDfield
param.Field[string]

Body param:

formatuuid
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
V1UsageListWithGroupsParamsWindowSizeHourconst
"HOUR"
V1UsageListWithGroupsParamsWindowSizeDayconst
"DAY"
V1UsageListWithGroupsParamsWindowSizeNoneconst
"NONE"
Limitfield
optional
param.Field[int64]

Query param: Max number of results that should be returned

minimum1
maximum100
NextPagefield
optional
param.Field[string]

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

CurrentPeriodfield
optional
param.Field[bool]

Body param: If true, will return the usage for the current billing period. Will return an error if the customer is currently uncontracted or starting_on and ending_before are specified when this is true.

EndingBeforefield
optional
param.Field[Time]

Body param:

formatdate-time
GroupByfield
optional

Body param:

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. Omit this if you'd like all values for the key returned.

StartingOnfield
optional
param.Field[Time]

Body param:

formatdate-time
Returns
V1UsageListWithGroupsResponsestruct
Hide ParametersShow Parameters
EndingBeforeTime
formatdate-time
GroupKeystring
GroupValuestring
StartingOnTime
formatdate-time
Valuefloat64
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"),
  )
  page, err := client.V1.Usage.ListWithGroups(context.TODO(), metronome.V1UsageListWithGroupsParams{
    BillableMetricID: metronome.F("222796fd-d29c-429e-89b2-549fabda4ed6"),
    CustomerID: metronome.F("04ca7e72-4229-4a6e-ab11-9f7376fccbcb"),
    WindowSize: metronome.F(metronome.V1UsageListWithGroupsParamsWindowSize("day")),
    EndingBefore: metronome.F(time.Now()),
    GroupBy: metronome.F(metronome.V1UsageListWithGroupsParamsGroupBy{
      Key: metronome.F("region"),
      Values: metronome.F([]string{"US-East", "US-West", "EU-Central"}),
    }),
    StartingOn: metronome.F(time.Now()),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
200 Example
{
  "data": [
    {
      "ending_before": "2019-12-27T18:11:19.117Z",
      "group_key": "group_key",
      "group_value": "group_value",
      "starting_on": "2019-12-27T18:11:19.117Z",
      "value": 0
    }
  ],
  "next_page": "next_page"
}