(Benefits)
- List - List Benefits
- Create - Create Benefit
- Get - Get Benefit
- Update - Update Benefit
- Delete - Delete Benefit
- Grants - List Benefit Grants
List benefits.
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.List(ctx, nil, nil, nil, nil)
if err != nil {
log.Fatal(err)
}
if res.ListResourceBenefit != 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. |
organizationID |
*operations.BenefitsListQueryParamOrganizationIDFilter | ➖ | Filter by organization ID. |
typeFilter |
*operations.BenefitTypeFilter | ➖ | Filter by benefit type. |
page |
*int64 | ➖ | Page number, defaults to 1. |
limit |
*int64 | ➖ | Size of a page, defaults to 10. Maximum is 100. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.BenefitsListResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Create a benefit.
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.Benefits.Create(ctx, components.CreateBenefitCreateBenefitDownloadablesCreate(
components.BenefitDownloadablesCreate{
Description: "yuck forager beneath please shadowy foodstuffs welcome",
Properties: components.BenefitDownloadablesCreateProperties{
Files: []string{
"<value>",
},
},
},
))
if err != nil {
log.Fatal(err)
}
if res.Benefit != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.BenefitCreate | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.BenefitsCreateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Get a benefit by ID.
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, "<value>")
if err != nil {
log.Fatal(err)
}
if res.Benefit != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.BenefitsGetResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Update a benefit.
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.Benefits.Update(ctx, "<value>", operations.CreateBenefitsUpdateBenefitUpdateBenefitGitHubRepositoryUpdate(
components.BenefitGitHubRepositoryUpdate{
Properties: &components.BenefitGitHubRepositoryCreateProperties{
RepositoryOwner: "polarsource",
RepositoryName: "private_repo",
Permission: components.BenefitGitHubRepositoryCreatePropertiesPermissionTriage,
},
},
))
if err != nil {
log.Fatal(err)
}
if res.Benefit != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | N/A |
requestBody |
operations.BenefitsUpdateBenefitUpdate | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.BenefitsUpdateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.NotPermitted | 403 | application/json |
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Delete a benefit.
Warning
Every grants associated with the benefit will be revoked. Users will lose access to the benefit.
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.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 | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.BenefitsDeleteResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.NotPermitted | 403 | application/json |
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
List the individual grants for a benefit.
It's especially useful to check if a user has been granted a benefit.
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: "<value>",
})
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
}
}
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
operations.BenefitsGrantsRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.BenefitsGrantsResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |