POST
/
v1
/
meters
package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Meters.Create(ctx, components.MeterCreate{
        Name: "<value>",
        Filter: components.Filter{
            Conjunction: components.FilterConjunctionAnd,
            Clauses: []components.Clauses{},
        },
        Aggregation: components.CreateMeterCreateAggregationAvg(
            components.PropertyAggregation{
                Func: components.FuncSum,
                Property: "<value>",
            },
        ),
        OrganizationID: polargo.String("1dbfc517-0bbf-4301-9ba8-555ca42b9737"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Meter != nil {
        // handle response
    }
}
{
  "metadata": {},
  "created_at": "2023-11-07T05:31:56Z",
  "modified_at": "2023-11-07T05:31:56Z",
  "id": "<string>",
  "name": "<string>",
  "filter": {
    "conjunction": "and",
    "clauses": [
      {
        "property": "<string>",
        "operator": "eq",
        "value": "<string>"
      }
    ]
  },
  "aggregation": {
    "func": "count"
  },
  "organization_id": "<string>"
}

Authorizations

Authorization
string
header
required

You can generate an Organization Access Token from your organization's settings.

Body

application/json
name
string
required

The name of the meter. Will be shown on customer's invoices and usage.

Minimum length: 3
filter
object
required

The filter to apply on events that'll be used to calculate the meter.

aggregation
object
required

The aggregation to apply on the filtered events to calculate the meter.

metadata
object

Key-value object allowing you to store additional information.

The key must be a string with a maximum length of 40 characters. The value must be either:

  • A string with a maximum length of 500 characters
  • An integer
  • A floating-point number
  • A boolean

You can store up to 50 key-value pairs.

organization_id
string | null

The ID of the organization owning the meter. Required unless you use an organization token.

Example:

"1dbfc517-0bbf-4301-9ba8-555ca42b9737"

Response

201
application/json
Meter created.
metadata
object
required
created_at
string
required

Creation timestamp of the object.

modified_at
string | null
required

Last modification timestamp of the object.

id
string
required

The ID of the object.

name
string
required

The name of the meter. Will be shown on customer's invoices and usage.

filter
object
required

The filter to apply on events that'll be used to calculate the meter.

aggregation
object
required

The aggregation to apply on the filtered events to calculate the meter.

organization_id
string
required

The ID of the organization owning the meter.

Was this page helpful?