class

Polar::Api::Benefits

Inherits Reference < Object

API client for benefits operations

Constants

Log = ::Log.for(self)

Constructors

new(client : Client)

Creates a new Benefits instance

@param client [Client] The Polar API client instance

Source

Instance methods

Create Benefit

Create a benefit.

Scopes: benefits:write

Endpoint: POST /v1/benefits/

Parameters:

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

Returns: Polar::Models::Benefit

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source
delete(id : String)

Delete Benefit

Delete a benefit.

[!WARNING] Every grants associated with the benefit will be revoked. Users will lose access to the benefit.

Scopes: benefits:write

Endpoint: DELETE /v1/benefits/{id}

Parameters:

  • id (required): Path parameter

Returns: JSON response string

Raises:

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

Get Benefit

Get a benefit by ID.

Scopes: benefits:read benefits:write

Endpoint: GET /v1/benefits/{id}

Parameters:

  • id (required): Path parameter

Returns: Polar::Models::Benefit

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source
grants(id : String, is_granted : String | Nil = nil, customer_id : String | Nil = nil, page : Int32 | Nil = nil, limit : Int32 | Nil = nil) : Polar::Models::ListResource(Polar::Models::BenefitGrant)

List Benefit Grants

List the individual grants for a benefit.

It's especially useful to check if a user has been granted a benefit.

Scopes: benefits:read benefits:write

Endpoint: GET /v1/benefits/{id}/grants

Parameters:

  • id (required): Path parameter
  • is_granted (optional): Filter by granted status. If true, only granted benefits will be returned. If false, only revoked benefits will be returned.
  • customer_id (optional): Filter by customer.
  • page (optional): Page number, defaults to 1.
  • limit (optional): Size of a page, defaults to 10. Maximum is 100.

Returns: Polar::Models::ListResource(Polar::Models::BenefitGrant)

Raises:

  • ResourceNotFoundError on 404
  • NotPermittedError on 403
  • HTTPValidationError on 422
  • PolarError on other errors
Source
list(organization_id : String | Nil = nil, type : String | Nil = nil, query : String | Nil = nil, page : Int32 | Nil = nil, limit : Int32 | Nil = nil, sorting : String | Nil = nil, metadata : String | Nil = nil) : Polar::Models::ListResource(Polar::Models::Benefit)

List Benefits

List benefits.

Scopes: benefits:read benefits:write

Endpoint: GET /v1/benefits/

Parameters:

  • organization_id (optional): Filter by organization ID.
  • type (optional): Filter by benefit type.
  • query (optional): Filter by description.
  • 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::Benefit)

Raises:

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

Update Benefit

Update a benefit.

Scopes: benefits:write

Endpoint: PATCH /v1/benefits/{id}

Parameters:

  • id (required): Path parameter
  • body (required): Request body as Polar::Models::BenefitCustomUpdate

Returns: Polar::Models::Benefit

Raises:

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