Skip to main content
POST
/
v1
/
discounts
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.Discounts.Create(ctx, components.CreateDiscountCreateDiscountPercentageOnceForeverDurationCreate(
        components.DiscountPercentageOnceForeverDurationCreate{
            Duration: components.DiscountDurationOnce,
            Type: components.DiscountTypeFixed,
            BasisPoints: 449604,
            Name: "<value>",
            OrganizationID: polargo.Pointer("1dbfc517-0bbf-4301-9ba8-555ca42b9737"),
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.Discount != nil {
        switch res.Discount.Type {
            case components.DiscountUnionTypeDiscountFixedOnceForeverDuration:
                // res.Discount.DiscountFixedOnceForeverDuration is populated
            case components.DiscountUnionTypeDiscountFixedRepeatDuration:
                // res.Discount.DiscountFixedRepeatDuration is populated
            case components.DiscountUnionTypeDiscountPercentageOnceForeverDuration:
                // res.Discount.DiscountPercentageOnceForeverDuration is populated
            case components.DiscountUnionTypeDiscountPercentageRepeatDuration:
                // res.Discount.DiscountPercentageRepeatDuration is populated
        }

    }
}
{
  "duration": "once",
  "type": "fixed",
  "amount": 123,
  "currency": "<string>",
  "amounts": {},
  "created_at": "2023-11-07T05:31:56Z",
  "modified_at": "2023-11-07T05:31:56Z",
  "id": "<string>",
  "metadata": {},
  "name": "<string>",
  "code": "<string>",
  "starts_at": "2023-11-07T05:31:56Z",
  "ends_at": "2023-11-07T05:31:56Z",
  "max_redemptions": 123,
  "redemptions_count": 123,
  "organization_id": "<string>",
  "products": [
    {
      "metadata": {},
      "id": "<string>",
      "created_at": "2023-11-07T05:31:56Z",
      "modified_at": "2023-11-07T05:31:56Z",
      "trial_interval": "day",
      "trial_interval_count": 123,
      "name": "<string>",
      "description": "<string>",
      "visibility": "draft",
      "recurring_interval": "day",
      "recurring_interval_count": 123,
      "is_recurring": true,
      "is_archived": true,
      "organization_id": "<string>"
    }
  ]
}

Documentation Index

Fetch the complete documentation index at: https://polar.sh/docs/llms.txt

Use this file to discover all available pages before exploring further.

Authorizations

Authorization
string
header
required

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

Body

application/json

Schema to create a fixed amount discount.

name
string
required

Name of the discount. Will be displayed to the customer when the discount is applied.

Minimum string length: 1
duration
enum<string>
required

For subscriptions, determines if the discount should be applied once on the first invoice, forever, or for a certain number of months determined by duration_in_months.

Available options:
once,
forever,
repeating
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.

code
string | null

Code customers can use to apply the discount during checkout. Must be between 3 and 256 characters long and contain only alphanumeric characters.If not provided, the discount can only be applied via the API.

starts_at
string<date-time> | null

Optional timestamp after which the discount is redeemable.

ends_at
string<date-time> | null

Optional timestamp after which the discount is no longer redeemable.

max_redemptions
integer | null

Optional maximum number of times the discount can be redeemed.

Required range: x >= 1
products
string<uuid4>[] | null

List of product IDs the discount can be applied to.

organization_id
string<uuid4> | null

The organization ID.

Example:

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

type
string
default:fixed
Allowed value: "fixed"
duration_in_months
integer | null

Number of months the discount should be applied.

Required when duration is repeating. Must be omitted otherwise.

For this to work on yearly pricing, you should multiply this by 12. For example, to apply the discount for 2 years, set this to 24.

Required range: 1 <= x <= 999
amount
integer | null
deprecated

Fixed amount to discount from the invoice total.

Required range: 0 <= x <= 999999999999
currency
enum<string> | null
default:usd
deprecated

The currency of the fixed amount discount.

Available options:
aed,
all,
amd,
aoa,
ars,
aud,
awg,
azn,
bam,
bbd,
bdt,
bif,
bmd,
bnd,
bob,
brl,
bsd,
bwp,
bzd,
cad,
cdf,
chf,
clp,
cny,
cop,
crc,
cve,
czk,
djf,
dkk,
dop,
dzd,
egp,
etb,
eur,
fjd,
fkp,
gbp,
gel,
gip,
gmd,
gnf,
gtq,
gyd,
hkd,
hnl,
htg,
huf,
idr,
ils,
inr,
isk,
jmd,
jpy,
kes,
kgs,
khr,
kmf,
krw,
kyd,
kzt,
lak,
lkr,
lrd,
lsl,
mad,
mdl,
mga,
mkd,
mnt,
mop,
mur,
mvr,
mwk,
mxn,
myr,
mzn,
nad,
ngn,
nio,
nok,
npr,
nzd,
pab,
pen,
pgk,
php,
pkr,
pln,
pyg,
qar,
ron,
rsd,
rwf,
sar,
sbd,
scr,
sek,
sgd,
shp,
sos,
srd,
szl,
thb,
tjs,
top,
try,
ttd,
twd,
tzs,
uah,
ugx,
usd,
uyu,
uzs,
vnd,
vuv,
wst,
xaf,
xcd,
xcg,
xof,
xpf,
yer,
zar,
zmw
amounts
Amounts · object

Map of currency to fixed amount to discount from the total. This allows specifying different discount amounts for different currencies.

Response

Discount created.

Schema for a fixed amount discount that is applied once or forever.

duration
enum<string>
required
Available options:
once,
forever,
repeating
type
enum<string>
required
Available options:
fixed,
percentage
amount
integer
required
deprecated
Example:

1000

currency
string
required
deprecated
Example:

"usd"

amounts
Amounts · object
required

Map of currency to fixed amount to discount from the total.

Example:
{ "eur": 900, "usd": 1000 }
created_at
string<date-time>
required

Creation timestamp of the object.

modified_at
string<date-time> | null
required

Last modification timestamp of the object.

id
string<uuid4>
required

The ID of the object.

metadata
object
required
name
string
required

Name of the discount. Will be displayed to the customer when the discount is applied.

code
string | null
required

Code customers can use to apply the discount during checkout.

starts_at
string<date-time> | null
required

Timestamp after which the discount is redeemable.

ends_at
string<date-time> | null
required

Timestamp after which the discount is no longer redeemable.

max_redemptions
integer | null
required

Maximum number of times the discount can be redeemed.

redemptions_count
integer
required

Number of times the discount has been redeemed.

organization_id
string<uuid4>
required

The organization ID.

Example:

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

products
DiscountProduct · object[]
required