Skip to content

Latest commit

 

History

History
370 lines (240 loc) · 32.2 KB

File metadata and controls

370 lines (240 loc) · 32.2 KB

MetricsSDK

(metrics)

Overview

Available Operations

get

Get metrics about your orders and subscriptions.

Currency values are output in cents.

Scopes: metrics:read

Example Usage

from datetime import date
import polar_sdk
from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.metrics.get(start_date=date.fromisoformat("2025-03-14"), end_date=date.fromisoformat("2025-03-18"), interval=polar_sdk.TimeInterval.HOUR, timezone="UTC", organization_id=None)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
start_date datetime ✔️ Start date.
end_date datetime ✔️ End date.
interval models.TimeInterval ✔️ Interval between two timestamps.
timezone Optional[str] Timezone to use for the timestamps. Default is UTC.
organization_id OptionalNullable[models.MetricsGetQueryParamOrganizationIDFilter] Filter by organization ID.
product_id OptionalNullable[models.MetricsGetQueryParamProductIDFilter] Filter by product ID.
billing_type OptionalNullable[models.QueryParamProductBillingTypeFilter] Filter by billing type. recurring will filter data corresponding to subscriptions creations or renewals. one_time will filter data corresponding to one-time purchases.
customer_id OptionalNullable[models.MetricsGetQueryParamCustomerIDFilter] Filter by customer ID.
metrics List[str] List of metric slugs to focus on. When provided, only the queries needed for these metrics will be executed, improving performance. If not provided, all metrics are returned.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.MetricsResponse

Errors

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

export

Export metrics as a CSV file.

Scopes: metrics:read

Example Usage

from datetime import date
import polar_sdk
from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.metrics.export(start_date=date.fromisoformat("2026-07-17"), end_date=date.fromisoformat("2024-05-06"), interval=polar_sdk.TimeInterval.YEAR, timezone="UTC", organization_id="1dbfc517-0bbf-4301-9ba8-555ca42b9737")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
start_date datetime ✔️ Start date.
end_date datetime ✔️ End date.
interval models.TimeInterval ✔️ Interval between two timestamps.
timezone Optional[str] Timezone to use for the timestamps. Default is UTC.
organization_id OptionalNullable[models.MetricsExportQueryParamOrganizationIDFilter] Filter by organization ID.
product_id OptionalNullable[models.MetricsExportQueryParamProductIDFilter] Filter by product ID.
billing_type OptionalNullable[models.MetricsExportQueryParamProductBillingTypeFilter] Filter by billing type. recurring will filter data corresponding to subscriptions creations or renewals. one_time will filter data corresponding to one-time purchases.
customer_id OptionalNullable[models.MetricsExportQueryParamCustomerIDFilter] Filter by customer ID.
metrics List[str] List of metric slugs to include in the export. If not provided, all metrics are exported.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.MetricsExportResponse

Errors

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

limits

Get the interval limits for the metrics endpoint.

Scopes: metrics:read

Example Usage

from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.metrics.limits()

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.MetricsLimits

Errors

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

list_dashboards

List user-defined metric dashboards.

Scopes: metrics:read

Example Usage

from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.metrics.list_dashboards(organization_id="1dbfc517-0bbf-4301-9ba8-555ca42b9737")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
organization_id OptionalNullable[models.MetricsListDashboardsQueryParamOrganizationIDFilter] Filter by organization ID.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

List[models.MetricDashboardSchema]

Errors

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

create_dashboard

Create a user-defined metric dashboard.

Scopes: metrics:write

Example Usage

from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.metrics.create_dashboard(request={
        "name": "<value>",
        "organization_id": "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
request models.MetricDashboardCreate ✔️ The request object to use for the request.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.MetricDashboardSchema

Errors

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

get_dashboard

Get a user-defined metric dashboard by ID.

Scopes: metrics:read

Example Usage

from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.metrics.get_dashboard(id="<value>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The metric dashboard ID.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.MetricDashboardSchema

Errors

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

update_dashboard

Update a user-defined metric dashboard.

Scopes: metrics:write

Example Usage

from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.metrics.update_dashboard(id="<value>", metric_dashboard_update={})

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The metric dashboard ID.
metric_dashboard_update models.MetricDashboardUpdate ✔️ N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.MetricDashboardSchema

Errors

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

delete_dashboard

Delete a user-defined metric dashboard.

Scopes: metrics:write

Example Usage

from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    polar.metrics.delete_dashboard(id="<value>")

    # Use the SDK ...

Parameters

Parameter Type Required Description
id str ✔️ The metric dashboard ID.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Errors

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