Skip to content

Latest commit

 

History

History
306 lines (230 loc) · 14 KB

README.md

File metadata and controls

306 lines (230 loc) · 14 KB

CustomFields

(CustomFields)

Overview

Available Operations

  • List - List Custom Fields
  • Create - Create Custom Field
  • Get - Get Custom Field
  • Update - Update Custom Field
  • Delete - Delete Custom Field

List

List custom fields.

Example Usage

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
            }
        }
    }
}

Parameters

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.

Response

*operations.CustomFieldsListResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Create

Create a custom field.

Example Usage

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
    }
}

Parameters

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.

Response

*operations.CustomFieldsCreateResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Get

Get a custom field by ID.

Example Usage

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
    }
}

Parameters

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.

Response

*operations.CustomFieldsGetResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Update

Update a custom field.

Example Usage

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
    }
}

Parameters

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.

Response

*operations.CustomFieldsUpdateResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Delete a custom field.

Example Usage

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
    }
}

Parameters

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.

Response

*operations.CustomFieldsDeleteResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*