(CustomFields)
- List - List Custom Fields
- Create - Create Custom Field
- Get - Get Custom Field
- Update - Update Custom Field
- Delete - Delete Custom Field
List custom fields.
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.CustomFields.List(ctx, operations.CustomFieldsListRequest{})
if err != nil {
log.Fatal(err)
}
if res.ListResourceCustomField != 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.CustomFieldsListRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomFieldsListResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Create a custom field.
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.CustomFields.Create(ctx, components.CreateCustomFieldCreateCustomFieldCreateSelect(
components.CustomFieldCreateSelect{
Slug: "<value>",
Name: "<value>",
Properties: components.CustomFieldSelectProperties{
Options: []components.CustomFieldSelectOption{
components.CustomFieldSelectOption{
Value: "<value>",
Label: "<value>",
},
},
},
},
))
if err != nil {
log.Fatal(err)
}
if res.CustomField != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.CustomFieldCreate | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomFieldsCreateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Get a custom field 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.CustomFields.Get(ctx, "<value>")
if err != nil {
log.Fatal(err)
}
if res.CustomField != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | The custom field ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomFieldsGetResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Update a custom field.
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.CustomFields.Update(ctx, "<value>", components.CreateCustomFieldUpdateCustomFieldUpdateNumber(
components.CustomFieldUpdateNumber{},
))
if err != nil {
log.Fatal(err)
}
if res.CustomField != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | The custom field ID. |
customFieldUpdate |
components.CustomFieldUpdate | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomFieldsUpdateResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |
Delete a custom field.
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.CustomFields.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 custom field ID. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CustomFieldsDeleteResponse, error
Error Type | Status Code | Content Type |
---|---|---|
apierrors.ResourceNotFound | 404 | application/json |
apierrors.HTTPValidationError | 422 | application/json |
apierrors.APIError | 4XX, 5XX | */* |