### Go: Get Product by ID Example Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/products/README.md Illustrates how to fetch a product by its ID using the Polar Go SDK. The example initializes the SDK with an access token, invokes the `Products.Get` method, and includes basic error handling and response processing. ```go 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.Products.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Product != nil { // handle response } } ``` -------------------------------- ### Go Example: Get Customer by ID Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/customers/README.md Demonstrates how to retrieve a customer by their ID using the Polar Go SDK. This example includes initializing the SDK with security credentials, making the API call, and basic error handling. ```go 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.Customers.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Customer != nil { // handle response } } ``` -------------------------------- ### Go: Get Discount by ID Example Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/discounts/README.md Demonstrates how to use the Polar Go SDK to fetch a discount by its ID. This example initializes the SDK with a security token and handles the API response or any errors. ```go 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.Discounts.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Discount != nil { // handle response } } ``` -------------------------------- ### Go Example: List Customer Portal Downloadables Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/downloadables/README.md This Go example demonstrates how to list downloadables using the `polargo` SDK. It initializes the SDK, authenticates with a customer session using `POLAR_CUSTOMER_SESSION` environment variable, and includes logic for paginating through 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.Downloadables.List(ctx, operations.CustomerPortalDownloadablesListSecurity{ CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"), }, polargo.Pointer(operations.CreateCustomerPortalDownloadablesListQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), nil, polargo.Int64(1), polargo.Int64(10)) if err != nil { log.Fatal(err) } if res.ListResourceDownloadableRead != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Go Example: Get a License Key Activation Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/licensekeys/README.md This Go code snippet demonstrates how to initialize the Polar Go SDK client with an access token and then use the `LicenseKeys.GetActivation` method to retrieve a specific license key activation. It includes basic error handling and a placeholder for response processing. ```go 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.LicenseKeys.GetActivation(ctx, "", "") if err != nil { log.Fatal(err) } if res.LicenseKeyActivationRead != nil { // handle response } } ``` -------------------------------- ### Go: Update Product Example Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/products/README.md Shows how to update an existing product using the Polar Go SDK. The example sets up the SDK, calls the `Products.Update` method with the product ID and update payload, and includes error handling. ```go 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.Products.Update(ctx, "", components.ProductUpdate{}) if err != nil { log.Fatal(err) } if res.Product != nil { // handle response } } ``` -------------------------------- ### Go Example: List Polar License Keys Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarlicensekeys/README.md Demonstrates how to list license keys using the Polar Go SDK. This example initializes the SDK, makes a paginated List call with security credentials and optional filters, and iterates through the 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: os.Getenv("POLAR_CUSTOMER_SESSION"), }, polargo.Pointer(operations.CreateCustomerPortalLicenseKeysListQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), nil, polargo.Int64(1), polargo.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 } } } } ``` -------------------------------- ### List Products using Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/products/README.md This Go example demonstrates how to list products using the Polar Go SDK. It initializes the SDK with an access token, then calls the `Products.List` method, optionally filtering by organization ID. The example also illustrates how to paginate through the results. ```go package main import( "context" os" polargo "github.com/polarsource/polar-go" "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.Products.List(ctx, operations.ProductsListRequest{ OrganizationID: polargo.Pointer(operations.CreateProductsListQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), }) if err != nil { log.Fatal(err) } if res.ListResourceProduct != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Go Example: Update Benefit Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/benefits/README.md Illustrates how to update a benefit using the Polar Go SDK, showing SDK setup, the update method call, and basic response handling. ```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.Benefits.Update(ctx, "", operations.CreateBenefitsUpdateBenefitUpdateBenefitCustomUpdate( components.BenefitCustomUpdate{}, )) if err != nil { log.Fatal(err) } if res.Benefit != nil { // handle response } } ``` -------------------------------- ### List Files using Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/files/README.md This Go example demonstrates how to list files using the Polar Go SDK. It initializes the SDK with an access token, then calls the `Files.List` method, handling pagination to retrieve all available file resources. The example shows how to iterate through paginated results. ```go package main import( "context" "os" polargo "github.com/polarsource/polar-go" "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.Files.List(ctx, polargo.Pointer(operations.CreateFilesListQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), nil, polargo.Int64(1), polargo.Int64(10)) if err != nil { log.Fatal(err) } if res.ListResourceFileRead != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Go Example: Get Customer Payment Methods Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarcustomers/README.md Demonstrates how to retrieve saved payment methods for an authenticated customer using the Polar Go SDK. This example includes setting up the client, handling security, and iterating through 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.Customers.GetPaymentMethods(ctx, operations.CustomerPortalCustomersGetPaymentMethodsSecurity{ CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"), }, polargo.Int64(1), polargo.Int64(10)) if err != nil { log.Fatal(err) } if res.ListResourceUnionPaymentMethodCardPaymentMethodGeneric != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Example Usage: Get Downloadable Item in Go Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/downloadables/README.md Demonstrates how to use the `Get` method of the `CustomerPortal.Downloadables` service to retrieve a specific downloadable item using the Polar Go SDK. It initializes the SDK, makes the API call, and handles potential errors. ```go package main import( "context" polargo "github.com/polarsource/polar-go" "log" ) func main() { ctx := context.Background() s := polargo.New() res, err := s.CustomerPortal.Downloadables.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Any != nil { // handle response } } ``` -------------------------------- ### Go Example for Updating a File Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/files/README.md Demonstrates how to update an existing file using the polar-go SDK. This example includes setting up the client with security, making an update call, and basic error handling. ```go 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.Files.Update(ctx, "", components.FilePatch{}) if err != nil { log.Fatal(err) } if res.ResponseFilesUpdate != nil { // handle response } } ``` -------------------------------- ### Go SDK Example: Generate Customer Order Invoice Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarorders/README.md Demonstrates how to use the Polar Go SDK to trigger the generation of an invoice for a customer order, including context setup and error handling. ```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.Orders.GenerateInvoice(ctx, operations.CustomerPortalOrdersGenerateInvoiceSecurity{ CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"), }, "") if err != nil { log.Fatal(err) } if res.Any != nil { // handle response } } ``` -------------------------------- ### Go Example: Listing Benefit Grants with Pagination Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/benefits/README.md Demonstrates how to initialize the Polar Go SDK, authenticate with an access token, and list individual benefit grants for a specified ID. The example includes handling for paginated responses and potential errors. ```go package main import( "context" os" polargo "github.com/polarsource/polar-go" "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.Benefits.Grants(ctx, operations.BenefitsGrantsRequest{ ID: "", }) if err != nil { log.Fatal(err) } if res.ListResourceBenefitGrant != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Go: Update Discount Example Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/discounts/README.md Illustrates how to update an existing discount using the Polar Go SDK. This example shows SDK initialization, passing the discount ID, and the `DiscountUpdate` payload, along with basic error handling. ```go 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.Discounts.Update(ctx, "", components.DiscountUpdate{}) if err != nil { log.Fatal(err) } if res.Discount != nil { // handle response } } ``` -------------------------------- ### Go SDK Example: List Payments Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/payments/README.md Demonstrates how to use the Polar Go SDK to list payments. It shows SDK initialization with security, making a paginated request, and filtering by organization ID. The example includes error handling and iteration through results. ```go package main import( "context" os" polargo "github.com/polarsource/polar-go" "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.Payments.List(ctx, operations.PaymentsListRequest{ OrganizationID: polargo.Pointer(operations.CreatePaymentsListQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), }) if err != nil { log.Fatal(err) } if res.ListResource != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Go Example: Get Meter Quantities over Time Period Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/meters/README.md Demonstrates how to use the Polar Go SDK to retrieve quantities for a specific meter within a defined start and end timestamp. It initializes the SDK with a security token and calls the `Meters.Quantities` method, specifying the meter ID, time range, and interval. ```go 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.Meters.Quantities(ctx, operations.MetersQuantitiesRequest{ ID: "", StartTimestamp: types.MustTimeFromString("2025-11-25T04:37:16.823Z"), EndTimestamp: types.MustTimeFromString("2025-11-26T17:06:00.727Z"), Interval: components.TimeIntervalDay, }) if err != nil { log.Fatal(err) } if res.MeterQuantities != nil { // handle response } } ``` -------------------------------- ### Go SDK Example: Fetch Order Invoice Data Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/orders/README.md Illustrates how to use the Polar Go SDK to fetch an order's invoice data. This example demonstrates SDK initialization, authentication, making the API call, and basic error handling. ```go 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.Orders.Invoice(ctx, "") if err != nil { log.Fatal(err) } if res.OrderInvoice != nil { // handle response } } ``` -------------------------------- ### Install Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/README.md To add the SDK as a dependency to your project. ```bash go get github.com/polarsource/polar-go ``` -------------------------------- ### Go SDK: Validate License Key Example Usage Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarlicensekeys/README.md This Go example demonstrates how to validate a license key using the Polar Go SDK. It shows the necessary imports, context initialization, SDK instantiation, and the call to the `Validate` method, along with basic error handling and response processing. ```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 } } ``` -------------------------------- ### Go Example: Get Benefit by ID Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/benefits/README.md Demonstrates how to use the Polar Go SDK to retrieve a benefit by its ID, including SDK initialization and error handling. ```go 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.Benefits.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Benefit != nil { // handle response } } ``` -------------------------------- ### Go Example: Get Authenticated User Information Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/oauth2/README.md Demonstrates how to use the Polar Go SDK to retrieve information about the authenticated user. This example initializes the client with an access token, makes a call to the `Userinfo` endpoint, and includes basic error handling and response processing. ```go 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.Oauth2.Userinfo(ctx) if err != nil { log.Fatal(err) } if res.ResponseOauth2Userinfo != nil { // handle response } } ``` -------------------------------- ### Go Example: Get Checkout Session by ID Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/checkouts/README.md Illustrates how to retrieve a checkout session by its ID using the Polar Go SDK. This example demonstrates client initialization with security, making the API call, and basic error handling. ```go 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.Checkouts.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Checkout != nil { // handle response } } ``` -------------------------------- ### Initialize One-Time Products (Go) Source: https://github.com/polarsource/polar-go/blob/main/docs/models/components/onetimeproducts.md Provides examples for initializing one-time products with different numeric types, specifically integers and floating-point numbers, using the `components` package. ```go oneTimeProducts := components.CreateOneTimeProductsInteger(int64{/* values here */}) ``` ```go oneTimeProducts := components.CreateOneTimeProductsNumber(float64{/* values here */}) ``` -------------------------------- ### Get OAuth2 Client by ID (Go Example) Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/clients/README.md This Go example demonstrates how to retrieve an OAuth2 client using its client ID. It initializes the Polar Go SDK client with an access token and then calls the `Oauth2.Clients.Get` method. The response or any errors are then handled. ```Go 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.Oauth2.Clients.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Any != nil { // handle response } } ``` -------------------------------- ### Go SDK Example: Get Payment by ID Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/payments/README.md Illustrates how to retrieve a single payment by its ID using the Polar Go SDK. The example covers SDK initialization, calling the `Payments.Get` method with a placeholder ID, and basic response handling. ```go 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.Payments.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Payment != nil { // handle response } } ``` -------------------------------- ### Retrieve Order and Subscription Metrics with Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/metrics/README.md This Go example demonstrates how to fetch detailed metrics for orders and subscriptions using the Polar Go SDK. It shows how to initialize the client with an access token and make a 'Get' request, specifying a date range, interval, and optional organization ID. The API returns currency values in cents and requires 'metrics:read' scope. ```go 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-03-14"), EndDate: types.MustDateFromString("2025-03-18"), Interval: components.TimeIntervalHour, OrganizationID: polargo.Pointer(operations.CreateMetricsGetQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), }) if err != nil { log.Fatal(err) } if res.MetricsResponse != nil { // handle response } } ``` ```APIDOC Parameters: - Name: ctx Type: context.Context Required: true Description: The context to use for the request. - Name: request Type: operations.MetricsGetRequest Required: true Description: The request object to use for the request. - Name: opts Type: []operations.Option Required: false Description: The options for this request. ``` ```APIDOC Response: Type: *operations.MetricsGetResponse, error ``` ```APIDOC Errors: - Type: apierrors.HTTPValidationError Status Code: 422 Content Type: application/json - Type: apierrors.APIError Status Code: 4XX, 5XX Content Type: */* ``` -------------------------------- ### Get Customer Portal Organization by Slug in Go Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarorganizations/README.md This Go example demonstrates how to initialize the Polar Go SDK client, authenticate using an access token, and retrieve a customer portal organization by its slug. It includes basic error handling and a placeholder for processing the successful response. ```go 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.CustomerPortal.Organizations.Get(ctx, "") if err != nil { log.Fatal(err) } if res.CustomerOrganization != nil { // handle response } } ``` -------------------------------- ### Go Example: Cancel Customer Subscription Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarsubscriptions/README.md Demonstrates how to use the Polar Go client to cancel a customer subscription, including context setup, security configuration, and error handling for the API call. ```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.Subscriptions.Cancel(ctx, operations.CustomerPortalSubscriptionsCancelSecurity{ CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"), }, "") if err != nil { log.Fatal(err) } if res.CustomerSubscription != nil { // handle response } } ``` -------------------------------- ### Go: Retrieve Customer State by ID Example Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/customers/README.md Illustrates how to use the Polar Go SDK to fetch a customer's state using their internal ID. This example covers SDK initialization, making the API call, and basic error handling. ```go 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.Customers.GetState(ctx, "") if err != nil { log.Fatal(err) } if res.CustomerState != nil { // handle response } } ``` -------------------------------- ### Create Product using Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/products/README.md This Go example demonstrates how to create a new product using the Polar Go SDK. It initializes the SDK with an access token and then calls the `Products.Create` method, providing essential product details such as name, recurring interval, and pricing configurations. ```go 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.Products.Create(ctx, components.ProductCreate{ Name: "", RecurringInterval: components.SubscriptionRecurringIntervalYear.ToPointer(), Prices: []components.ProductCreatePrices{ components.CreateProductCreatePricesProductPriceFixedCreate( components.ProductPriceFixedCreate{ PriceAmount: 677078, }, ), components.CreateProductCreatePricesProductPriceCustomCreate( components.ProductPriceCustomCreate{}, ), }, OrganizationID: polargo.String("1dbfc517-0bbf-4301-9ba8-555ca42b9737"), }) if err != nil { log.Fatal(err) } if res.Product != nil { // handle response } } ``` -------------------------------- ### List Organizations Example in Go Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/organizations/README.md Demonstrates how to list organizations using the `polar-go` SDK. It initializes the client with an access token, calls the `List` method, and handles pagination to retrieve all organization items. ```go 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.Organizations.List(ctx, nil, polargo.Int64(1), polargo.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 } } } } ``` -------------------------------- ### Go Example: Get Event by ID Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/events/README.md Demonstrates how to retrieve a specific event by its ID using the Polar Go SDK. This example initializes the SDK with a security token and includes basic error handling. ```Go 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.Events.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Event != nil { // handle response } } ``` -------------------------------- ### Go Example: Update an Organization Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/organizations/README.md Demonstrates how to update an organization using the Polar Go SDK, including SDK initialization with security and basic error handling. ```go 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.Organizations.Update(ctx, "1dbfc517-0bbf-4301-9ba8-555ca42b9737", components.OrganizationUpdate{}) if err != nil { log.Fatal(err) } if res.Organization != nil { // handle response } } ``` -------------------------------- ### Go Example: Activate a License Key Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarlicensekeys/README.md Demonstrates how to activate a license key instance using the Polar Go SDK. It initializes the SDK, constructs a LicenseKeyActivate request with the key, organization ID, and label, and handles the API response or any errors. ```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.Activate(ctx, components.LicenseKeyActivate{ Key: "", OrganizationID: "", Label: "", }) if err != nil { log.Fatal(err) } if res.LicenseKeyActivationRead != nil { // handle response } } ``` -------------------------------- ### Go SDK: Get Checkout Link by ID Example Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/checkoutlinks/README.md Demonstrates how to retrieve a specific checkout link using its unique identifier with the Polar Go SDK. This example initializes the SDK with a security token and handles the response or any errors. ```go 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.CheckoutLinks.Get(ctx, "") if err != nil { log.Fatal(err) } if res.CheckoutLink != nil { // handle response } } ``` -------------------------------- ### Go SDK Example: Update Product Benefits Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/products/README.md Illustrates how to use the Polar Go SDK to update benefits for a specific product. It covers initializing the SDK with security, making the `UpdateBenefits` call, and handling the response or errors. ```go 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.Products.UpdateBenefits(ctx, "", components.ProductBenefitsUpdate{ Benefits: []string{ "", "", "", }, }) if err != nil { log.Fatal(err) } if res.Product != nil { // handle response } } ``` -------------------------------- ### Initialize Polar Go SDK and List Organizations Source: https://github.com/polarsource/polar-go/blob/main/USAGE.md This Go code snippet demonstrates how to initialize the Polar Go SDK using an access token from environment variables and then list organizations with pagination. It includes basic error handling and shows how to iterate through paginated results using the `Next()` method. ```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.Int64(1), polargo.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 } } } } ``` -------------------------------- ### API Fields Reference Source: https://github.com/polarsource/polar-go/blob/main/docs/models/components/ordercustomer.md Details the available fields for a customer object, including their data types, whether they are required, and a brief description. Examples are provided where applicable. ```APIDOC Fields: - ID: Type: string Required: true Description: The ID of the customer. Example: 992fae2a-2a17-4b7a-8d9e-e287cf90131b - CreatedAt: Type: time.Time Required: true Description: Creation timestamp of the object. - ModifiedAt: Type: time.Time Required: true Description: Last modification timestamp of the object. - Metadata: Type: map[string]components.OrderCustomerMetadata Required: true Description: N/A ``` -------------------------------- ### List Discounts using Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/discounts/README.md This Go example demonstrates how to list discounts for a specific organization using the Polar Go SDK. It initializes the SDK with an access token, makes a paginated request, and iterates through the results to handle items. ```go package main import( "context" os" polargo "github.com/polarsource/polar-go" "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.Discounts.List(ctx, operations.DiscountsListRequest{ OrganizationID: polargo.Pointer(operations.CreateDiscountsListQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), }) if err != nil { log.Fatal(err) } if res.ListResourceDiscount != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Go SDK Example: Get a Meter by ID Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/meters/README.md This Go example demonstrates how to retrieve a specific meter using its ID. It initializes the Polar Go SDK client with an access token, then calls the `Meters.Get` method. The response can be handled if the meter is found, otherwise, errors are logged. ```Go 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.Meters.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Meter != nil { // handle response } } ``` -------------------------------- ### API Reference: Customer Portal Downloadables Get Parameters and Response Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/downloadables/README.md Details the parameters, response structure, and potential errors for retrieving a specific customer portal downloadable. ```APIDOC Parameters: ctx: context.Context (Required) - The context to use for the request. token: string (Required) - N/A opts: []operations.Option (Optional) - The options for this request. Response: Type: operations.CustomerPortalDownloadablesCustomerPortalDownloadablesGetResponse, error Errors: apierrors.HTTPValidationError: Status Code 422, Content Type application/json apierrors.APIError: Status Code 4XX, 5XX, Content Type */* ``` -------------------------------- ### Get a Specific Order by ID using Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/orders/README.md This Go example shows how to retrieve a single order by its ID using the Polar Go SDK. It initializes the SDK with an access token and calls the 'Get' method with the order ID. The operation requires the 'orders:read' scope. Ensure 'POLAR_ACCESS_TOKEN' is set in your environment. ```go 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.Orders.Get(ctx, "") if err != nil { log.Fatal(err) } if res.Order != nil { // handle response } } ``` ```APIDOC Parameters for Get Order: - ctx: context.Context (Required) - The context to use for the request. - id: *string (Required) - The order ID. - opts: []operations.Option (Optional) - The options for this request. ``` -------------------------------- ### PolarLicenseKeys API Overview and Scopes Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarlicensekeys/README.md Overview of the PolarLicenseKeys API, listing available operations (List, Get, Validate, Activate, Deactivate) and detailing the required scopes for the List operation. ```APIDOC PolarLicenseKeys (*CustomerPortal.LicenseKeys) Available Operations: * List - List License Keys * Get - Get License Key * Validate - Validate License Key * Activate - Activate License Key * Deactivate - Deactivate License Key List Operation Details: Scopes: customer_portal:read, customer_portal:write ``` -------------------------------- ### Get Authenticated Customer in Go Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/polarcustomers/README.md This Go example demonstrates how to retrieve an authenticated customer's details using the `polargo` SDK. It initializes the SDK, sets up security with a customer session, and handles the response or any errors. ```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.Customers.Get(ctx, operations.CustomerPortalCustomersGetSecurity{ CustomerSession: os.Getenv("POLAR_CUSTOMER_SESSION"), }) if err != nil { log.Fatal(err) } if res.CustomerPortalCustomer != nil { // handle response } } ``` -------------------------------- ### Get Customer Meter by ID using Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/customermeters/README.md This Go example demonstrates how to retrieve a single customer meter by its ID. It initializes the Polar Go SDK with an access token and then calls the `CustomerMeters.Get` method with the meter's ID. ```Go 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.CustomerMeters.Get(ctx, "") if err != nil { log.Fatal(err) } if res.CustomerMeter != nil { // handle response } } ``` -------------------------------- ### Go Example: Get Customer by External ID Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/customers/README.md Demonstrates how to retrieve a customer using their external ID with the Polar Go SDK. It initializes the client with a security token, calls the `GetExternal` method, and handles potential errors and the successful response. ```go 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.Customers.GetExternal(ctx, "") if err != nil { log.Fatal(err) } if res.Customer != nil { // handle response } } ``` -------------------------------- ### Available SDK Server Environments Source: https://github.com/polarsource/polar-go/blob/main/README.md Lists the predefined server environments available for the SDK, including their names, base URLs, and descriptions. Users can select a target environment like `production` or `sandbox` using the `WithServer(server string)` option during SDK client initialization. ```APIDOC | Name | Server | Description | |---|---|---| | `production` | `https://api.polar.sh` | Production environment | | `sandbox` | `https://sandbox-api.polar.sh` | Sandbox environment | ``` -------------------------------- ### Get a Polar Checkout Session by Client Secret in Go Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/checkouts/README.md This Go example shows how to retrieve a Polar checkout session using its client secret via the `polargo` SDK. It initializes the SDK and fetches the session, including basic error handling. ```go package main import( "context" polargo "github.com/polarsource/polar-go" "log" ) func main() { ctx := context.Background() s := polargo.New() res, err := s.Checkouts.ClientGet(ctx, "") if err != nil { log.Fatal(err) } if res.CheckoutPublic != nil { // handle response } } ``` -------------------------------- ### List Subscriptions using Polar Go SDK Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/subscriptions/README.md This Go example demonstrates how to list subscriptions using the Polar Go SDK. It initializes the SDK with an access token, makes a List request with an optional organization ID filter, and iterates through paginated results. Requires `context`, `os`, `polargo`, and `log` packages. ```go package main import( "context" os" polargo "github.com/polarsource/polar-go" "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.List(ctx, operations.SubscriptionsListRequest{ OrganizationID: polargo.Pointer(operations.CreateOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), }) if err != nil { log.Fatal(err) } if res.ListResourceSubscription != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Go Example: Introspect an OAuth2 Access Token Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/oauth2/README.md Illustrates how to use the Polar Go SDK to get information about an OAuth2 access token. It initializes the SDK, calls the `Introspect` method with the token and client credentials, and handles potential errors or successful responses. ```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.Oauth2.Introspect(ctx, components.IntrospectTokenRequest{ Token: "", ClientID: "", ClientSecret: "" }) if err != nil { log.Fatal(err) } if res.IntrospectTokenResponse != nil { // handle response } } ``` -------------------------------- ### CustomerSessions Create API Reference Source: https://github.com/polarsource/polar-go/blob/main/docs/sdks/customersessions/README.md Detailed API documentation for the `CustomerSessions.Create` operation, outlining required parameters, expected response types, and potential error conditions for API consumers. ```APIDOC Operation: Create Customer Session Scopes: customer_sessions:write Parameters: - ctx: context.Context (Required) Description: The context to use for the request. - request: operations.CustomerSessionsCreateCustomerSessionCreate (Required) Description: The request object to use for the request. - opts: []operations.Option (Optional) Description: The options for this request. Response: - Type: operations.CustomerSessionsCreateResponse, error Errors: - apierrors.HTTPValidationError Status Code: 422 Content Type: application/json - apierrors.APIError Status Code: 4XX, 5XX Content Type: */* ```