Skip to main content
POST
/
v1
/
benefits
/
Go (SDK)
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.Benefits.Create(ctx, components.CreateBenefitCreateLicenseKeys(
        components.BenefitLicenseKeysCreate{
            Description: "mature emergent at outside arrogantly gadzooks zealous equatorial notwithstanding",
            OrganizationID: polargo.Pointer("1dbfc517-0bbf-4301-9ba8-555ca42b9737"),
            Properties: components.BenefitLicenseKeysCreateProperties{},
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.Benefit != nil {
        switch res.Benefit.Type {
            case components.BenefitUnionTypeCustom:
                // res.Benefit.BenefitCustom is populated
            case components.BenefitUnionTypeDiscord:
                // res.Benefit.BenefitDiscord is populated
            case components.BenefitUnionTypeDownloadables:
                // res.Benefit.BenefitDownloadables is populated
            case components.BenefitUnionTypeFeatureFlag:
                // res.Benefit.BenefitFeatureFlag is populated
            case components.BenefitUnionTypeGithubRepository:
                // res.Benefit.BenefitGitHubRepository is populated
            case components.BenefitUnionTypeLicenseKeys:
                // res.Benefit.BenefitLicenseKeys is populated
            case components.BenefitUnionTypeMeterCredit:
                // res.Benefit.BenefitMeterCredit is populated
        }

    }
}
from polar_sdk import Polar


with Polar(
    access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:

    res = polar.benefits.create(request={
        "type": "license_keys",
        "description": "mature emergent at outside arrogantly gadzooks zealous equatorial notwithstanding",
        "properties": {},
    })

    # Handle response
    print(res)
import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.benefits.create({
    type: "license_keys",
    description: "mature emergent at outside arrogantly gadzooks zealous equatorial notwithstanding",
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    properties: {},
  });

  console.log(result);
}

run();
declare(strict_types=1);

require 'vendor/autoload.php';

use Polar;
use Polar\Models\Components;

$sdk = Polar\Polar::builder()
    ->setSecurity(
        '<YOUR_BEARER_TOKEN_HERE>'
    )
    ->build();

$request = new Components\BenefitLicenseKeysCreate(
    description: 'mature emergent at outside arrogantly gadzooks zealous equatorial notwithstanding',
    organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
    properties: new Components\BenefitLicenseKeysCreateProperties(),
);

$response = $sdk->benefits->create(
    request: $request
);

if ($response->benefit !== null) {
    // handle response
}
curl --request POST \
  --url https://api.polar.sh/v1/benefits/ \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "type": "<string>",
  "description": "<string>",
  "properties": {
    "note": "<string>"
  },
  "metadata": {},
  "organization_id": "1dbfc517-0bbf-4301-9ba8-555ca42b9737"
}
'
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    type: '<string>',
    description: '<string>',
    properties: {note: '<string>'},
    metadata: {},
    organization_id: '1dbfc517-0bbf-4301-9ba8-555ca42b9737'
  })
};

fetch('https://api.polar.sh/v1/benefits/', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
HttpResponse<String> response = Unirest.post("https://api.polar.sh/v1/benefits/")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"type\": \"<string>\",\n  \"description\": \"<string>\",\n  \"properties\": {\n    \"note\": \"<string>\"\n  },\n  \"metadata\": {},\n  \"organization_id\": \"1dbfc517-0bbf-4301-9ba8-555ca42b9737\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.polar.sh/v1/benefits/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"type\": \"<string>\",\n  \"description\": \"<string>\",\n  \"properties\": {\n    \"note\": \"<string>\"\n  },\n  \"metadata\": {},\n  \"organization_id\": \"1dbfc517-0bbf-4301-9ba8-555ca42b9737\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "<string>",
  "created_at": "2023-11-07T05:31:56Z",
  "modified_at": "2023-11-07T05:31:56Z",
  "type": "<string>",
  "description": "<string>",
  "selectable": true,
  "deletable": true,
  "is_deleted": true,
  "organization_id": "<string>",
  "metadata": {},
  "properties": {
    "note": "<string>"
  },
  "visibility_configurable": true
}
{
  "detail": [
    {
      "loc": [
        "<string>"
      ],
      "msg": "<string>",
      "type": "<string>",
      "input": "<unknown>",
      "ctx": {}
    }
  ]
}

Authorizations

Authorization
string
header
required

You can generate an Organization Access Token from your organization's settings.

Body

application/json

Schema to create a benefit of type custom.

type
string
required
Allowed value: "custom"
description
string
required

The description of the benefit. Will be displayed on products having this benefit.

Required string length: 3 - 42
properties
BenefitCustomCreateProperties · object
required

Properties for creating a benefit of type custom.

metadata
Metadata · object

Key-value object allowing you to store additional information.

The key must be a string with a maximum length of 40 characters. The value must be either:

  • A string with a maximum length of 500 characters
  • An integer
  • A floating-point number
  • A boolean

You can store up to 50 key-value pairs.

organization_id
string<uuid4> | null

The organization ID.

Example:

"1dbfc517-0bbf-4301-9ba8-555ca42b9737"

visibility
enum<string> | null

The visibility of the benefit in the customer portal.

Available options:
draft,
private,
public

Response

Benefit created.

A benefit of type custom.

Use it to grant any kind of benefit that doesn't fit in the other types.

id
string<uuid4>
required

The ID of the benefit.

created_at
string<date-time>
required

Creation timestamp of the object.

modified_at
string<date-time> | null
required

Last modification timestamp of the object.

type
string
required
Allowed value: "custom"
description
string
required

The description of the benefit.

selectable
boolean
required

Whether the benefit is selectable when creating a product.

deletable
boolean
required

Whether the benefit is deletable.

is_deleted
boolean
required

Whether the benefit is deleted.

organization_id
string<uuid4>
required

The ID of the organization owning the benefit.

metadata
object
required
visibility
enum<string>
required

The visibility of the benefit in the customer portal.

Available options:
draft,
private,
public
properties
BenefitCustomProperties · object
required

Properties for a benefit of type custom.

visibility_configurable
boolean
required