class

Polar::Api::Subscriptions

Inherits Reference < Object

API client for subscriptions operations

Constants

Log = ::Log.for(self)

Constructors

new(client : Client)

Creates a new Subscriptions instance

@param client [Client] The Polar API client instance

Source

Instance methods

Create Subscription

Create a subscription programmatically.

This endpoint only allows to create subscription on free products. For paid products, use the checkout flow.

No initial order will be created and no confirmation email will be sent.

Scopes: subscriptions:write

Endpoint: POST /v1/subscriptions/

Parameters:

  • body (required): Request body as Polar::Models::SubscriptionCreateCustomer

Returns: Polar::Models::Subscription

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source
export(organization_id : String | Nil = nil)

Export Subscriptions

Export subscriptions as a CSV file.

Scopes: subscriptions:read subscriptions:write

Endpoint: GET /v1/subscriptions/export

Parameters:

  • organization_id (optional): Filter by organization ID.

Returns: JSON response string

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source

Get Subscription

Get a subscription by ID.

Scopes: subscriptions:read subscriptions:write

Endpoint: GET /v1/subscriptions/{id}

Parameters:

  • id (required): The subscription ID.

Returns: Polar::Models::Subscription

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source
list(organization_id : String | Nil = nil, product_id : String | Nil = nil, customer_id : String | Nil = nil, external_customer_id : String | Nil = nil, discount_id : String | Nil = nil, active : String | Nil = nil, page : Int32 | Nil = nil, limit : Int32 | Nil = nil, sorting : String | Nil = nil, metadata : String | Nil = nil) : Polar::Models::ListResource(Polar::Models::Subscription)

List Subscriptions

List subscriptions.

Scopes: subscriptions:read subscriptions:write

Endpoint: GET /v1/subscriptions/

Parameters:

  • organization_id (optional): Filter by organization ID.
  • product_id (optional): Filter by product ID.
  • customer_id (optional): Filter by customer ID.
  • external_customer_id (optional): Filter by customer external ID.
  • discount_id (optional): Filter by discount ID.
  • active (optional): Filter by active or inactive subscription.
  • page (optional): Page number, defaults to 1.
  • limit (optional): Size of a page, defaults to 10. Maximum is 100.
  • sorting (optional): Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign - before the criteria name to sort by descending order.
  • metadata (optional): Filter by metadata key-value pairs. It uses the deepObject style, e.g. ?metadata[key]=value.

Returns: Polar::Models::ListResource(Polar::Models::Subscription)

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source

Revoke Subscription

Revoke a subscription, i.e cancel immediately.

Scopes: subscriptions:write

Endpoint: DELETE /v1/subscriptions/{id}

Parameters:

  • id (required): The subscription ID.

Returns: Polar::Models::Subscription

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source

Update Subscription

Update a subscription.

Scopes: subscriptions:write

Endpoint: PATCH /v1/subscriptions/{id}

Parameters:

  • id (required): The subscription ID.
  • body (required): Request body as Polar::Models::SubscriptionUpdate

Returns: Polar::Models::Subscription

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source