(Customers)
- List - List Customers
- Create - Create Customer
- Get - Get Customer
- Update - Update Customer
- Delete - Delete Customer
- GetExternal - Get Customer by External ID
- UpdateExternal - Update Customer by External ID
- DeleteExternal - Delete Customer by External ID
- GetState - Get Customer State
- GetStateExternal - Get Customer State by External ID
List customers.
Scopes: customers:read
customers:write
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.Customers.List(ctx, operations.CustomersListRequest{
OrganizationID: polargo.Pointer(operations.CreateCustomersListQueryParamOrganizationIDFilterArrayOfStr(
[]string{
"1dbfc517-0bbf-4301-9ba8-555ca42b9737",
},
)),
})
if err != nil {
log.Fatal(err)
}
if res.ListResourceCustomer != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
operations.CustomersListRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersListResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Create a customer.
Scopes: customers:write
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.Customers.Create(ctx, components.CustomerCreate{
ExternalID: polargo.String("usr_1337"),
Email: "customer@example.com",
Name: polargo.String("John Doe"),
BillingAddress: &components.Address{
Country: "SE",
},
TaxID: []*components.CustomerCreateTaxID{
polargo.Pointer(components.CreateCustomerCreateTaxIDStr(
"FR61954506077",
)),
polargo.Pointer(components.CreateCustomerCreateTaxIDStr(
"eu_vat",
)),
},
OrganizationID: polargo.String("1dbfc517-0bbf-4301-9ba8-555ca42b9737"),
})
if err != nil {
log.Fatal(err)
}
if res.Customer != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.CustomerCreate | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersCreateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Get a customer by ID.
Scopes: customers:read
customers:write
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, "<value>")
if err != nil {
log.Fatal(err)
}
if res.Customer != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | The customer ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersGetResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Update a customer.
Scopes: customers:write
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.Customers.Update(ctx, "<value>", components.CustomerUpdate{
ExternalID: polargo.String("usr_1337"),
Email: polargo.String("customer@example.com"),
Name: polargo.String("John Doe"),
BillingAddress: &components.Address{
Country: "FR",
},
TaxID: []*components.CustomerUpdateTaxID{
polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
"FR61954506077",
)),
polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
"eu_vat",
)),
},
})
if err != nil {
log.Fatal(err)
}
if res.Customer != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | The customer ID. |
customerUpdate |
components.CustomerUpdate | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersUpdateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Delete a customer.
This action cannot be undone and will immediately:
- Cancel any active subscriptions for the customer
- Revoke all their benefits
- Clear any
external_id
Use it only in the context of deleting a user within your own service. Otherwise, use more granular API endpoints to cancel a specific subscription or revoke certain benefits.
Note: The customers information will nonetheless be retained for historic orders and subscriptions.
Scopes: customers:write
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.Delete(ctx, "<value>")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | The customer ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersDeleteResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Get a customer by external ID.
Scopes: customers:read
customers:write
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, "<id>")
if err != nil {
log.Fatal(err)
}
if res.Customer != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
externalID |
string | ✔️ | The customer external ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersGetExternalResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Update a customer by external ID.
Scopes: customers:write
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.Customers.UpdateExternal(ctx, "<id>", components.CustomerUpdate{
ExternalID: polargo.String("usr_1337"),
Email: polargo.String("customer@example.com"),
Name: polargo.String("John Doe"),
BillingAddress: &components.Address{
Country: "US",
},
TaxID: []*components.CustomerUpdateTaxID{
polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
"FR61954506077",
)),
polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
"eu_vat",
)),
},
})
if err != nil {
log.Fatal(err)
}
if res.Customer != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
externalID |
string | ✔️ | The customer external ID. |
customerUpdate |
components.CustomerUpdate | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersUpdateExternalResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Delete a customer by external ID.
Immediately cancels any active subscriptions and revokes any active benefits.
Scopes: customers:write
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.DeleteExternal(ctx, "<id>")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
externalID |
string | ✔️ | The customer external ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersDeleteExternalResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Get a customer state by ID.
The customer state includes information about the customer's active subscriptions and benefits.
It's the ideal endpoint to use when you need to get a full overview of a customer's status.
Scopes: customers:read
customers:write
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, "<value>")
if err != nil {
log.Fatal(err)
}
if res.CustomerState != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | The customer ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersGetStateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Get a customer state by external ID.
The customer state includes information about the customer's active subscriptions and benefits.
It's the ideal endpoint to use when you need to get a full overview of a customer's status.
Scopes: customers:read
customers:write
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.GetStateExternal(ctx, "<id>")
if err != nil {
log.Fatal(err)
}
if res.CustomerState != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
externalID |
string | ✔️ | The customer external ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomersGetStateExternalResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |