Skip to content
This repository was archived by the owner on Jul 22, 2026. It is now read-only.

Latest commit

 

History

History
503 lines (373 loc) · 25.4 KB

File metadata and controls

503 lines (373 loc) · 25.4 KB

Webhooks

Overview

Available Operations

ListWebhookEndpoints

List webhook endpoints.

Scopes: webhooks:read webhooks:write

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.Webhooks.ListWebhookEndpoints(ctx, polargo.Pointer(operations.CreateQueryParamOrganizationIDStr(
        "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    )), polargo.Pointer[int64](1), polargo.Pointer[int64](10))
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceWebhookEndpoint != 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.
organizationID *operations.QueryParamOrganizationID Filter by organization ID.
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.

Response

*operations.WebhooksListWebhookEndpointsResponse, error

Errors

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

CreateWebhookEndpoint

Create a webhook endpoint.

Scopes: webhooks:write

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.Webhooks.CreateWebhookEndpoint(ctx, components.WebhookEndpointCreate{
        URL: "https://webhook.site/cb791d80-f26e-4f8c-be88-6e56054192b0",
        Format: components.WebhookFormatSlack,
        Events: []components.WebhookEventType{
            components.WebhookEventTypeSubscriptionUncanceled,
        },
        OrganizationID: polargo.Pointer("1dbfc517-0bbf-4301-9ba8-555ca42b9737"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.WebhookEndpoint != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.WebhookEndpointCreate ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.WebhooksCreateWebhookEndpointResponse, error

Errors

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

GetWebhookEndpoint

Get a webhook endpoint by ID.

Scopes: webhooks:read webhooks:write

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.Webhooks.GetWebhookEndpoint(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.WebhookEndpoint != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The webhook endpoint ID.
opts []operations.Option The options for this request.

Response

*operations.WebhooksGetWebhookEndpointResponse, error

Errors

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

DeleteWebhookEndpoint

Delete a webhook endpoint.

Scopes: webhooks:write

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.Webhooks.DeleteWebhookEndpoint(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 webhook endpoint ID.
opts []operations.Option The options for this request.

Response

*operations.WebhooksDeleteWebhookEndpointResponse, error

Errors

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

UpdateWebhookEndpoint

Update a webhook endpoint.

Scopes: webhooks:write

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.Webhooks.UpdateWebhookEndpoint(ctx, "<value>", components.WebhookEndpointUpdate{
        URL: polargo.Pointer("https://webhook.site/cb791d80-f26e-4f8c-be88-6e56054192b0"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.WebhookEndpoint != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The webhook endpoint ID.
webhookEndpointUpdate components.WebhookEndpointUpdate ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.WebhooksUpdateWebhookEndpointResponse, error

Errors

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

ResetWebhookEndpointSecret

Regenerate a webhook endpoint secret.

Scopes: webhooks:write

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.Webhooks.ResetWebhookEndpointSecret(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.WebhookEndpoint != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The webhook endpoint ID.
opts []operations.Option The options for this request.

Response

*operations.WebhooksResetWebhookEndpointSecretResponse, error

Errors

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

ListWebhookDeliveries

List webhook deliveries.

Deliveries are all the attempts to deliver a webhook event to an endpoint.

Scopes: webhooks:read webhooks:write

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.Webhooks.ListWebhookDeliveries(ctx, operations.WebhooksListWebhookDeliveriesRequest{})
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceWebhookDelivery != 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.WebhooksListWebhookDeliveriesRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.WebhooksListWebhookDeliveriesResponse, error

Errors

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

RedeliverWebhookEvent

Schedule the re-delivery of a webhook event.

Scopes: webhooks:write

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.Webhooks.RedeliverWebhookEvent(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.Any != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The webhook event ID.
opts []operations.Option The options for this request.

Response

*operations.WebhooksRedeliverWebhookEventResponse, error

Errors

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