Skip to content

Latest commit

 

History

History
175 lines (123 loc) · 11 KB

README.md

File metadata and controls

175 lines (123 loc) · 11 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

import { Polar } from "@polar-sh/sdk";
import { RFCDate } from "@polar-sh/sdk/types/rfcdate.js";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.metrics.get({
    startDate: new RFCDate("2025-02-06"),
    endDate: new RFCDate("2024-09-04"),
    interval: "week",
    organizationId: [
      "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    ],
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { metricsGet } from "@polar-sh/sdk/funcs/metricsGet.js";
import { RFCDate } from "@polar-sh/sdk/types/rfcdate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await metricsGet(polar, {
    startDate: new RFCDate("2025-02-06"),
    endDate: new RFCDate("2024-09-04"),
    interval: "week",
    organizationId: [
      "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    ],
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request operations.MetricsGetRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.MetricsResponse>

Errors

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

limits

Get the interval limits for the metrics endpoint.

Scopes: metrics:read

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.metrics.limits();

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { metricsLimits } from "@polar-sh/sdk/funcs/metricsLimits.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await metricsLimits(polar);

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.MetricsLimits>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*