### Quickstart Source: https://polar.sh/docs/integrate/sdk/golang A quickstart example demonstrating how to initialize the SDK and list organizations. ```go package main import ( "context" polargo "github.com/polarsource/polar-go" "log" "os" ) func main() { ctx := context.Background() s s := polargo.New( polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil) if err != nil { log.Fatal(err) } if res.ListResourceOrganization != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### TypeScript SDK Quickstart Example Source: https://polar.sh/docs/llms-full.txt Quickstart example for the Polar TypeScript SDK, demonstrating asynchronous fetching of user benefits. It uses environment variables for the access token and server mode. ```typescript import { Polar } from '@polar-sh/sdk' const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN, server: process.env.POLAR_MODE || 'sandbox' // sandbox or production }) async function run() { const result = await polar.users.benefits.list({}) for await (const page of result) { // Handle the page console.log(page) } } run() ``` -------------------------------- ### Install Polar Go SDK Source: https://polar.sh/docs/integrate/sdk/golang Use 'go get' to install the Polar Go SDK. Ensure your Go environment is set up correctly. ```bash go get github.com/polarsource/polar-go ``` -------------------------------- ### Quickstart: List Organizations with Polar Go SDK Source: https://polar.sh/docs/integrate/sdk/golang This example shows how to initialize the Polar Go SDK with an access token and list organizations. It includes basic error handling and pagination logic. ```go package main import ( "context" polargo "github.com/polarsource/polar-go" "log" "os" ) func main() { ctx := context.Background() s := polargo.New( polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil) if err != nil { log.Fatal(err) } if res.ListResourceOrganization != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Get Meter Quantities Source: https://polar.sh/docs/api-reference/meters/get-quantities This example demonstrates how to retrieve meter quantities using the Polar SDK. You need to provide the meter ID, start and end timestamps, and the desired interval. ```APIDOC ## Get Meter Quantities ### Description Retrieves historical meter quantities for a given meter ID within a specified time range and interval. ### Method GET ### Endpoint `/api/v1/meters/{id}/quantities` ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the meter. #### Query Parameters - **start_timestamp** (string) - Required - The start of the time range (ISO 8601 format). - **end_timestamp** (string) - Required - The end of the time range (ISO 8601 format). - **interval** (string) - Required - The time interval for aggregation (e.g., `day`, `hour`, `month`). ### Response #### Success Response (200) - **quantities** (array) - An array of meter quantity objects. - **timestamp** (string) - The timestamp for the quantity. - **quantity** (number) - The measured quantity. - **total** (number) - The total quantity for the period. #### Error Response (404) - **error** (string) - Indicates the error type, e.g., `ResourceNotFound`. - **detail** (string) - A message describing the error. ### Request Example (SDK - TypeScript) ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.meters.quantities({ id: "", startTimestamp: new Date("2025-11-25T04:37:16.823Z"), endTimestamp: new Date("2025-11-26T17:06:00.727Z"), interval: "day", }); console.log(result); } run(); ``` ### Response Example (Success) ```json { "quantities": [ { "timestamp": "2025-11-25T00:00:00Z", "quantity": 50 }, { "timestamp": "2025-11-26T00:00:00Z", "quantity": 75 } ], "total": 125 } ``` ``` -------------------------------- ### Go Quickstart: List Organizations Source: https://polar.sh/docs/llms-full.txt Demonstrates how to initialize the Go SDK and list organizations, including handling pagination. ```go package main import ( "context" polargo "github.com/polarsource/polar-go" "log" "os" ) func main() { ctx := context.Background() s := polargo.New( polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil) if err != nil { log.Fatal(err) } if res.ListResourceOrganization != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Get Claim Info - TypeScript SDK Source: https://polar.sh/docs/api-reference/customer-seats/get-claim-info This TypeScript SDK example shows how to call the getClaimInfo method with an invitation token and log the result. It includes basic setup for the Polar SDK. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar(); async function run() { const result = await polar.customerSeats.getClaimInfo({ invitationToken: "", }); console.log(result); } run(); ``` -------------------------------- ### PHP Quickstart: List Organizations Source: https://polar.sh/docs/llms-full.txt Demonstrates initializing the PHP SDK with a bearer token and listing organizations. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; $sdk = Polar\Polar::builder() ->setSecurity('') ->build(); $responses = $sdk->organizations->list( page: 1, limit: 10 ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } } ``` -------------------------------- ### Get Order by ID in TypeScript Source: https://polar.sh/docs/api-reference/customer-portal/orders/get This TypeScript example demonstrates how to get an order by ID using the Polar SDK. It utilizes environment variables for authentication. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar(); async function run() { const result = await polar.customerPortal.orders.get({ customerSession: process.env["POLAR_CUSTOMER_SESSION"] ?? "", }, { id: "", }); console.log(result); } run(); ``` -------------------------------- ### Create Product (PHP SDK) Source: https://polar.sh/docs/api-reference/products/create Example of creating a product using the PHP SDK. This example demonstrates setting up a one-time product with fixed and custom pricing. ```APIDOC ## Create Product (PHP SDK) ### Description This example demonstrates how to create a new product using the PHP SDK. It includes setting up a one-time product with both fixed and custom pricing details. ### Method `sdk->products->create()` ### Parameters #### Request Body - **request** (object) - Required - An instance of `Components\ProductCreateOneTime` or `Components\ProductCreateRecurring`. ### Request Example ```php setSecurity('') ->build(); $request = new Components\ProductCreateOneTime( name: '', prices: [ new Components\ProductPriceFixedCreate( priceCurrency: Components\PresentmentCurrency::Usd, priceAmount: 677078, ), new Components\ProductPriceCustomCreate( priceCurrency: Components\PresentmentCurrency::Usd, ), ], organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737', recurringInterval: 'year', ); $response = $sdk->products->create( request: $request ); if ($response->product !== null) { // handle response } ``` ### Response #### Success Response - **product** (object | null) - Details of the created product if successful. ``` -------------------------------- ### Create Subscription (Go SDK) Source: https://polar.sh/docs/api-reference/subscriptions/create Use the Go SDK to create a subscription. Ensure you have set the POLAR_ACCESS_TOKEN environment variable. This example demonstrates creating a subscription for a free product. ```go package main import( "context" "os" polargo "github.com/polarsource/polar-go" "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.Subscriptions.Create(ctx, operations.CreateSubscriptionsCreateSubscriptionCreateSubscriptionCreateCustomer( components.SubscriptionCreateCustomer{ ProductID: "d8dd2de1-21b7-4a41-8bc3-ce909c0cfe23", CustomerID: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", }, )) if err != nil { log.Fatal(err) } if res.Subscription != nil { switch res.Subscription.Discount.Type { case components.SubscriptionDiscountTypeDiscountFixedOnceForeverDurationBase: // res.Subscription.Discount.DiscountFixedOnceForeverDurationBase is populated case components.SubscriptionDiscountTypeDiscountFixedRepeatDurationBase: // res.Subscription.Discount.DiscountFixedRepeatDurationBase is populated case components.SubscriptionDiscountTypeDiscountPercentageOnceForeverDurationBase: // res.Subscription.Discount.DiscountPercentageOnceForeverDurationBase is populated case components.SubscriptionDiscountTypeDiscountPercentageRepeatDurationBase: // res.Subscription.Discount.DiscountPercentageRepeatDurationBase is populated } } } ``` -------------------------------- ### Get Metrics Limits (PHP SDK) Source: https://polar.sh/docs/api-reference/metrics/get-limits Use the PHP SDK to get metrics limits. Ensure you have installed the SDK via Composer and replaced `` with your token. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; $sdk = Polar\Polar::builder() ->setSecurity( '' ) ->build(); $response = $sdk->metrics->limits( ); if ($response->metricsLimits !== null) { // handle response } ``` -------------------------------- ### Create Subscription (PHP SDK) Source: https://polar.sh/docs/api-reference/subscriptions/create This PHP SDK example demonstrates creating a subscription for an existing customer using their customer ID. Remember to replace '' with your actual token. The product must be free. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; use Polar\Models\Components; $sdk = Polar\Polar::builder() ->setSecurity( '' ) ->build(); $request = new Components\SubscriptionCreateCustomer( productId: 'd8dd2de1-21b7-4a41-8bc3-ce909c0cfe23', customerId: '992fae2a-2a17-4b7a-8d9e-e287cf90131b', ); $response = $sdk->subscriptions->create( request: $request ); if ($response->subscription !== null) { // handle response } ``` -------------------------------- ### Get Order Receipt (Python SDK) Source: https://polar.sh/docs/api-reference/customer-portal/orders/get-receipt Use the Polar SDK to get a presigned URL for an order receipt. Ensure you have the SDK installed and provide your bearer token and the order ID. ```python import polar_sdk from polar_sdk import Polar with Polar() as polar: res = polar.customer_portal.orders.receipt(security=polar_sdk.CustomerPortalOrdersReceiptSecurity( customer_session="", ), id="") assert res is not None # Handle response print(res) ``` -------------------------------- ### Fetch Products with Pagination Source: https://polar.sh/docs/api-reference/introduction Example of how to fetch products using pagination parameters. The response includes pagination metadata. ```bash curl https://api.polar.sh/v1/products/?page=1&limit=100 \ -H "Authorization: Bearer $POLAR_OAT" \ -H "Accept: application/json" ``` ```json { "items": [ { "id": "...", "name": "Product 1", ... }, ... ], "pagination": { "total_count": 250, "max_page": 3 } } ``` -------------------------------- ### Run polar-migrate CLI Source: https://polar.sh/docs/migrate Execute this command to start the migration process from Lemon Squeezy to Polar. Ensure you have the latest version installed. ```bash npx polar-migrate@latest ``` -------------------------------- ### Get Organization Details in Go Source: https://polar.sh/docs/api-reference/customer-portal/get-organization Use this snippet to fetch an organization's details by providing its slug. Ensure you have the polar-go SDK installed and imported. ```go package main import( "context" polargo "github.com/polarsource/polar-go" "log" ) func main() { ctx := context.Background() s := polargo.New() res, err := s.CustomerPortal.Organizations.Get(ctx, "") if err != nil { log.Fatal(err) } if res.CustomerOrganizationData != nil { // handle response } } ``` -------------------------------- ### List Orders with PHP SDK Source: https://polar.sh/docs/api-reference/orders/list Use the PHP SDK to list orders. This example demonstrates setting up the SDK and making the request. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; use Polar\Models\Operations; $sdk = Polar\Polar::builder() ->setSecurity( '' ) ->build(); $request = new Operations\OrdersListRequest( organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737', ); $responses = $sdk->orders->list( request: $request ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } } ``` -------------------------------- ### Get Custom Field in TypeScript (SDK) Source: https://polar.sh/docs/api-reference/custom-fields/get Example of retrieving a custom field using the Polar TypeScript SDK. It utilizes the `POLAR_ACCESS_TOKEN` from environment variables or requires it to be set. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.customFields.get({ id: "", }); console.log(result); } run(); ``` -------------------------------- ### List Customer Subscriptions (Go SDK) Source: https://polar.sh/docs/api-reference/customer-portal/subscriptions/list Demonstrates how to list customer subscriptions using the Go SDK. Includes handling pagination and potential errors. ```go package main import( "context" polargo "github.com/polarsource/polar-go" "github.com/polarsource/polar-go/models/operations" "os" "log" ) func main() { ctx := context.Background() s := polargo.New() res, err := s.CustomerPortal.Subscriptions.List(ctx, operations.CustomerPortalSubscriptionsListRequest{}, operations.CustomerPortalSubscriptionsListSecurity{ CustomerSession: polargo.Pointer(os.Getenv("POLAR_CUSTOMER_SESSION")), }) if err != nil { log.Fatal(err) } if res.ListResourceCustomerSubscription != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Create File (PHP SDK) Source: https://polar.sh/docs/api-reference/files/create This PHP example illustrates how to create a file using the Polar SDK. Ensure you have installed the SDK via Composer and configured your security token. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; use Polar\Models\Components; $sdk = Polar\Polar::builder() ->setSecurity( '' ) ->build(); $request = new Components\DownloadableFileCreate( organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737', name: '', mimeType: '', size: 612128, upload: new Components\S3FileCreateMultipart( parts: [], ), ); $response = $sdk->files->create( request: $request ); if ($response->fileUpload !== null) { // handle response } ``` -------------------------------- ### Get Customer by External ID (TypeScript SDK) Source: https://polar.sh/docs/api-reference/customers/get-external Example of retrieving a customer by external ID using the Polar TypeScript SDK. Ensure your environment variable POLAR_ACCESS_TOKEN is set. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.customers.getExternal({ externalId: "", }); console.log(result); } run(); ``` -------------------------------- ### Core API Example Source: https://polar.sh/docs/api-reference Example of how to make a request to the Core API to retrieve products. ```APIDOC ## GET /v1/products/ ### Description Retrieves a list of products available through the Core API. ### Method GET ### Endpoint https://api.polar.sh/v1/products/ ### Parameters #### Query Parameters - **page** (integer) - Optional - Page number, starting from 1. - **limit** (integer) - Optional - Number of items to return per page (window size), defaults to 10, max 100. ### Request Example ```bash curl https://api.polar.sh/v1/products/ \ -H "Authorization: Bearer $POLAR_OAT" \ -H "Accept: application/json" ``` ### Response #### Success Response (200) - **pagination** (object) - Contains metadata about the current page and total results. - **total_count** (integer) - Total number of items matching your query across all pages. - **max_page** (integer) - Total number of pages available, given the current `limit` value. #### Response Example ```json { "data": [ { "id": "prod_1", "name": "Example Product 1", "price": 1000 }, { "id": "prod_2", "name": "Example Product 2", "price": 2000 } ], "pagination": { "total_count": 250, "max_page": 3 } } ``` ``` -------------------------------- ### Core API Example (Sandbox) Source: https://polar.sh/docs/api-reference/introduction Example of fetching products from the Core API in the sandbox environment using cURL. ```APIDOC ## Quick Examples ```bash curl https://sandbox-api.polar.sh/v1/products/ \ -H "Authorization: Bearer $POLAR_OAT_SANDBOX" \ -H "Accept: application/json" ``` ``` -------------------------------- ### Get Claim Info - PHP SDK Source: https://polar.sh/docs/api-reference/customer-seats/get-claim-info Use the PHP SDK to retrieve seat claim information. This example demonstrates initializing the SDK and calling the getClaimInfo method with the invitation token. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; $sdk = Polar\Polar::builder()->build(); $response = $sdk->customerSeats->getClaimInfo( invitationToken: '' ); if ($response->seatClaimInfo !== null) { // handle response } ``` -------------------------------- ### Create Subscription (Python SDK) Source: https://polar.sh/docs/api-reference/subscriptions/create Use the Python SDK to create a subscription. Replace "" with your actual token. This example shows how to initiate a subscription creation request. ```python from polar_sdk import Polar with Polar( access_token="", ) as polar: res = polar.subscriptions.create(request={ "product_id": "d8dd2de1-21b7-4a41-8bc3-ce909c0cfe23", "customer_id": "992fae2a-2a17-4b7a-8d9e-e287cf90131b", }) # Handle response print(res) ``` -------------------------------- ### Get Claim Info - Python SDK Source: https://polar.sh/docs/api-reference/customer-seats/get-claim-info The Python SDK allows you to fetch seat claim details using the invitation token. The example demonstrates how to instantiate the SDK and process the response. ```python from polar_sdk import Polar with Polar() as polar: res = polar.customer_seats.get_claim_info(invitation_token="") # Handle response print(res) ``` -------------------------------- ### Javascript LLM Ingestion Strategy Setup Source: https://polar.sh/docs/features/usage-based-billing/ingestion-strategies/llm-strategy Set up the LLM ingestion strategy in Javascript using the Polar SDK. This example shows how to wrap an LLM model and configure cost tracking. ```typescript import { Ingestion } from "@polar-sh/ingestion"; import { LLMStrategy } from "@polar-sh/ingestion/strategies/LLM"; import { generateText } from "ai"; import { openai } from "@ai-sdk/openai"; // Setup the LLM Ingestion Strategy const llmIngestion = Ingestion({accessToken: process.env.POLAR_ACCESS_TOKEN}) .strategy(new LLMStrategy(openai("gpt-4o"))) .cost((ctx) => ({ amount: 123, currency: "usd" })) // Optional: Set the cost of the LLM usage .ingest("openai-usage"); export async function POST(req: Request) { const { prompt }: { prompt: string } = await req.json(); // Get the wrapped LLM model with ingestion capabilities // Pass Customer Id to properly annotate the ingestion events with a specific customer const model = llmIngestion.client({ customerId: "xxx", }); const { text } = await generateText({ model, system: "You are a helpful assistant.", prompt, }); return Response.json({ text }); } ``` -------------------------------- ### SDK Initialization with Sandbox Server Source: https://polar.sh/docs/api-reference/introduction Demonstrates how to initialize the Polar SDKs for TypeScript, Python, Go, and PHP, specifying the sandbox server for testing. ```APIDOC ## Using SDKs All official SDKs accept a `server` parameter for sandbox usage: ```ts TypeScript theme={null} import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN!, server: "sandbox", // omit or use 'production' for live }); ``` ```py Python theme={null} from polar import Polar client = Polar( access_token=os.environ["POLAR_ACCESS_TOKEN"], server="sandbox", ) ``` ```go Go theme={null} s := polargo.New( polargo.WithServer("sandbox"), polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) ``` ```php PHP theme={null} $sdk = Polar\Polar::builder() ->setServer('sandbox') ->setSecurity(getenv('POLAR_ACCESS_TOKEN')) ->build(); ``` ``` -------------------------------- ### Core API Example (Production) Source: https://polar.sh/docs/api-reference/introduction Example of fetching products from the Core API in the production environment using cURL. ```APIDOC ## Quick Examples ```bash curl https://api.polar.sh/v1/products/ \ -H "Authorization: Bearer $POLAR_OAT" \ -H "Accept: application/json" ``` ``` -------------------------------- ### Quickstart Polar SDK in TypeScript Source: https://polar.sh/docs/integrate/sdk/typescript Initialize the Polar SDK with an access token and server mode, then list user benefits. Ensure your POLAR_ACCESS_TOKEN and POLAR_MODE environment variables are set. ```typescript import { Polar } from '@polar-sh/sdk' const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN, server: process.env.POLAR_MODE || 'sandbox' // sandbox or production }) async function run() { const result = await polar.users.benefits.list({}) for await (const page of result) { // Handle the page console.log(page) } } run() ``` -------------------------------- ### Get Meter by ID in TypeScript (SDK) Source: https://polar.sh/docs/api-reference/meters/get Fetch meter details with the Polar TypeScript SDK. Ensure the POLAR_ACCESS_TOKEN environment variable is set. This example demonstrates an asynchronous function to call the API. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.meters.get({ id: "", }); console.log(result); } run(); ``` -------------------------------- ### Validate License Key with Go SDK Source: https://polar.sh/docs/api-reference/customer-portal/license-keys/validate Use the Polar Go SDK to validate a license key. Ensure you have the SDK installed and imported correctly. This example shows how to initialize the SDK and make the validation call. ```go package main import( "context" polargo "github.com/polarsource/polar-go" "github.com/polarsource/polar-go/models/components" "log" ) func main() { ctx := context.Background() s := polargo.New() res, err := s.CustomerPortal.LicenseKeys.Validate(ctx, components.LicenseKeyValidate{ Key: "", OrganizationID: "", }) if err != nil { log.Fatal(err) } if res.ValidatedLicenseKey != nil { // handle response } } ``` -------------------------------- ### List Products with PHP SDK Source: https://polar.sh/docs/api-reference/products/list Use the PHP SDK to retrieve a list of products for a given organization. Ensure you have set up the SDK and your bearer token. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; use Polar\Models\Operations; $sdk = Polar\Polar::builder() ->setSecurity( '' ) ->build(); $request = new Operations\ProductsListRequest( organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737', ); $responses = $sdk->products->list( request: $request ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } } ``` -------------------------------- ### Get Metrics Data in PHP Source: https://polar.sh/docs/api-reference/metrics/get Use the Polar PHP SDK to fetch metrics. Configure the SDK with your bearer token and construct a MetricsGetRequest object with the start date, end date, interval, and organization ID. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Brick\DateTime\LocalDate; use Polar; use Polar\Models\Components; use Polar\Models\Operations; $sdk = Polar\Polar::builder() ->setSecurity( '' ) ->build(); $request = new Operations\MetricsGetRequest( startDate: LocalDate::parse('2025-03-14'), endDate: LocalDate::parse('2025-03-18'), interval: Components\TimeInterval::Hour, organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737', ); $response = $sdk->metrics->get( request: $request ); if ($response->metricsResponse !== null) { ``` -------------------------------- ### Activate License Key (PHP SDK) Source: https://polar.sh/docs/api-reference/customer-portal/license-keys/activate This example demonstrates how to activate a license key using the PHP SDK. ```APIDOC ## Activate License Key (PHP SDK) ### Description Activates a license key for a given organization using the PHP SDK. ### Method `$sdk->customerPortal->licenseKeys->activate(request)` ### Parameters #### Request Object - **key** (string) - Required - The license key to activate. - **organizationId** (string) - Required - The ID of the organization to activate the key for. - **label** (string) - Required - A label for the activation. ### Request Example ```php require 'vendor/autoload.php'; use Polar; use Polar\Models\Components; $sdk = Polar\Polar::builder()->build(); $request = new Components\LicenseKeyActivate( key: '', organizationId: '', label: '', ); $response = $sdk->customerPortal->licenseKeys->activate( request: $request ); if ($response->licenseKeyActivationRead !== null) { // handle response } ``` ### Response Returns details of the activated license key if successful. ``` -------------------------------- ### List Products (Python SDK) Source: https://polar.sh/docs/api-reference/products/list Shows how to list products using the Polar Python SDK. This example includes basic usage for listing products and handling pagination. ```python from polar_sdk import Polar with Polar( access_token="", ) as polar: res = polar.products.list(organization_id=None, page=1, limit=10) while res is not None: # Handle items res = res.next() ``` -------------------------------- ### List Claimed Subscriptions (PHP SDK) Source: https://polar.sh/docs/api-reference/customer-portal/seats/list-subscriptions Use the PHP SDK to list claimed subscriptions. Ensure you have the SDK installed and configured with your bearer token. The example shows how to set up the security context and make the API call. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; use Polar\Models\Operations; $sdk = Polar\Polar::builder()->build(); $requestSecurity = new Operations\CustomerPortalSeatsListClaimedSubscriptionsSecurity( customerSession: '', ); $responses = $sdk->customerPortal->seats->listClaimedSubscriptions( security: $requestSecurity, page: 1, limit: 10 ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } } ``` -------------------------------- ### Create Checkout Session with Customer IP Address (Python) Source: https://polar.sh/docs/llms-full.txt This Python snippet demonstrates how to forward the customer's IP address when creating a checkout session via the API. It's crucial for accurate geo-detection when your server's IP would otherwise be used. The example uses 'request.client.host' to get the IP. ```Python from polar_sdk import Polar with Polar(access_token="") as polar: checkout = polar.checkouts.create(request={ "products": [""], "customer_ip_address": request.client.host, }) ``` -------------------------------- ### Initialize Polar SDK in Sandbox (Go) Source: https://polar.sh/docs/llms-full.txt Create a new Go SDK client instance configured for the sandbox environment, using environment variables for the access token. ```go s := polargo.New( polargo.WithServer("sandbox"), polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) ``` -------------------------------- ### Install Polar CLI Source: https://polar.sh/docs/llms-full.txt Use this command to install the Polar CLI for local webhook testing. Ensure you have curl installed. ```bash curl -fsSL https://polar.sh/install.sh | bash ``` -------------------------------- ### List License Keys with Go SDK Source: https://polar.sh/docs/api-reference/customer-portal/license-keys/list Use the Go SDK to list license keys. Ensure you have set the POLAR_CUSTOMER_SESSION environment variable for authentication. This example shows how to handle paginated results. ```go package main import( "context" polargo "github.com/polarsource/polar-go" "os" "github.com/polarsource/polar-go/models/operations" "log" ) func main() { ctx := context.Background() s := polargo.New() res, err := s.CustomerPortal.LicenseKeys.List(ctx, operations.CustomerPortalLicenseKeysListSecurity{ CustomerSession: polargo.Pointer(os.Getenv("POLAR_CUSTOMER_SESSION")), }, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10)) if err != nil { log.Fatal(err) } if res.ListResourceLicenseKeyRead != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Install PHP SDK with Composer Source: https://polar.sh/docs/integrate/sdk/php Install the Polar PHP SDK using Composer. Ensure you have Composer installed and configured. ```bash composer require polar-sh/sdk ``` -------------------------------- ### Get Activation (PHP SDK) Source: https://polar.sh/docs/api-reference/license-keys/get-activation Use the PHP SDK to get a license key activation. Initialize the SDK with your bearer token and provide the required IDs. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; $sdk = Polar\Polar::builder() ->setSecurity( '' ) ->build(); $response = $sdk->licenseKeys->getActivation( id: '', activationId: '' ); if ($response->licenseKeyActivationRead !== null) { // handle response } ``` -------------------------------- ### Install Python SDK Source: https://polar.sh/docs/features/usage-based-billing/ingestion-strategies/llm-strategy Install the Polar SDK for Python using pip or uv. ```bash pip install polar-sdk ``` ```bash uv add polar-sdk ```