Skip to content

Latest commit

 

History

History
129 lines (95 loc) · 5.02 KB

README.md

File metadata and controls

129 lines (95 loc) · 5.02 KB

Metrics

(Metrics)

Overview

Available Operations

  • Get - Get Metrics
  • Limits - Get Metrics Limits

Get

Get metrics about your orders and subscriptions.

Currency values are output in cents.

Scopes: metrics:read

Example Usage

package main

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

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

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

    res, err := s.Metrics.Get(ctx, operations.MetricsGetRequest{
        StartDate: types.MustDateFromString("2025-02-06"),
        EndDate: types.MustDateFromString("2024-09-04"),
        Interval: components.TimeIntervalWeek,
        OrganizationID: polargo.Pointer(operations.CreateMetricsGetQueryParamOrganizationIDFilterArrayOfStr(
            []string{
                "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
            },
        )),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.MetricsResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.MetricsGetRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.MetricsGetResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Limits

Get the interval limits for the metrics endpoint.

Scopes: metrics:read

Example Usage

package main

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

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

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

    res, err := s.Metrics.Limits(ctx)
    if err != nil {
        log.Fatal(err)
    }
    if res.MetricsLimits != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
opts []operations.Option The options for this request.

Response

*operations.MetricsLimitsResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*