curl --request POST \
--url https://api.suby.fi/api/discount/create \
--header 'Content-Type: application/json' \
--header 'X-Suby-Api-Key: <api-key>' \
--data '
{
"name": "WELCOME10",
"productIds": [
"pro_abc123",
"pro_sub456"
],
"discountType": "FIXED",
"discountPercent": 10,
"discountAmountCents": 500,
"preApply": false,
"maxUses": 100,
"expiresAt": "2026-12-31T23:59:59Z",
"externalRef": "almanak_user_42",
"isActive": true
}
'import requests
url = "https://api.suby.fi/api/discount/create"
payload = {
"name": "WELCOME10",
"productIds": ["pro_abc123", "pro_sub456"],
"discountType": "FIXED",
"discountPercent": 10,
"discountAmountCents": 500,
"preApply": False,
"maxUses": 100,
"expiresAt": "2026-12-31T23:59:59Z",
"externalRef": "almanak_user_42",
"isActive": True
}
headers = {
"X-Suby-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Suby-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'WELCOME10',
productIds: ['pro_abc123', 'pro_sub456'],
discountType: 'FIXED',
discountPercent: 10,
discountAmountCents: 500,
preApply: false,
maxUses: 100,
expiresAt: '2026-12-31T23:59:59Z',
externalRef: 'almanak_user_42',
isActive: true
})
};
fetch('https://api.suby.fi/api/discount/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.suby.fi/api/discount/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'WELCOME10',
'productIds' => [
'pro_abc123',
'pro_sub456'
],
'discountType' => 'FIXED',
'discountPercent' => 10,
'discountAmountCents' => 500,
'preApply' => false,
'maxUses' => 100,
'expiresAt' => '2026-12-31T23:59:59Z',
'externalRef' => 'almanak_user_42',
'isActive' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Suby-Api-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.suby.fi/api/discount/create"
payload := strings.NewReader("{\n \"name\": \"WELCOME10\",\n \"productIds\": [\n \"pro_abc123\",\n \"pro_sub456\"\n ],\n \"discountType\": \"FIXED\",\n \"discountPercent\": 10,\n \"discountAmountCents\": 500,\n \"preApply\": false,\n \"maxUses\": 100,\n \"expiresAt\": \"2026-12-31T23:59:59Z\",\n \"externalRef\": \"almanak_user_42\",\n \"isActive\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Suby-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.suby.fi/api/discount/create")
.header("X-Suby-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"WELCOME10\",\n \"productIds\": [\n \"pro_abc123\",\n \"pro_sub456\"\n ],\n \"discountType\": \"FIXED\",\n \"discountPercent\": 10,\n \"discountAmountCents\": 500,\n \"preApply\": false,\n \"maxUses\": 100,\n \"expiresAt\": \"2026-12-31T23:59:59Z\",\n \"externalRef\": \"almanak_user_42\",\n \"isActive\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.suby.fi/api/discount/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Suby-Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"WELCOME10\",\n \"productIds\": [\n \"pro_abc123\",\n \"pro_sub456\"\n ],\n \"discountType\": \"FIXED\",\n \"discountPercent\": 10,\n \"discountAmountCents\": 500,\n \"preApply\": false,\n \"maxUses\": 100,\n \"expiresAt\": \"2026-12-31T23:59:59Z\",\n \"externalRef\": \"almanak_user_42\",\n \"isActive\": true\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"id": "dis_abc123",
"name": "WELCOME10",
"discountType": "PERCENT",
"discountPercent": 1000,
"discountAmountCents": null,
"preApply": true,
"expiresAt": "2023-11-07T05:31:56Z",
"maxUses": 123,
"externalRef": "almanak_user_42",
"isActive": true,
"products": [
{
"id": "<string>",
"name": "<string>",
"platform": "WEB"
}
]
}
}{
"success": false,
"error": {
"code": "PRODUCT_NOT_FOUND",
"message": "Product not found"
}
}{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or missing API key"
}
}Create a discount code
Creates a reusable discount code that customers can apply at checkout (or that you pre-apply
via the discountCode field on POST /api/payment/create / POST /api/subscription/create).
Discount type
PERCENT— setdiscountPercent(1–100).discountAmountCentsmust NOT be set.FIXED(default) — setdiscountAmountCents(integer, in cents). Applied in each target product’s own currency.discountPercentmust NOT be set.
Target products
productIds accepts either:
- the literal string
"all"— the code applies to all your products, or - a non-empty array of product IDs.
curl --request POST \
--url https://api.suby.fi/api/discount/create \
--header 'Content-Type: application/json' \
--header 'X-Suby-Api-Key: <api-key>' \
--data '
{
"name": "WELCOME10",
"productIds": [
"pro_abc123",
"pro_sub456"
],
"discountType": "FIXED",
"discountPercent": 10,
"discountAmountCents": 500,
"preApply": false,
"maxUses": 100,
"expiresAt": "2026-12-31T23:59:59Z",
"externalRef": "almanak_user_42",
"isActive": true
}
'import requests
url = "https://api.suby.fi/api/discount/create"
payload = {
"name": "WELCOME10",
"productIds": ["pro_abc123", "pro_sub456"],
"discountType": "FIXED",
"discountPercent": 10,
"discountAmountCents": 500,
"preApply": False,
"maxUses": 100,
"expiresAt": "2026-12-31T23:59:59Z",
"externalRef": "almanak_user_42",
"isActive": True
}
headers = {
"X-Suby-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Suby-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'WELCOME10',
productIds: ['pro_abc123', 'pro_sub456'],
discountType: 'FIXED',
discountPercent: 10,
discountAmountCents: 500,
preApply: false,
maxUses: 100,
expiresAt: '2026-12-31T23:59:59Z',
externalRef: 'almanak_user_42',
isActive: true
})
};
fetch('https://api.suby.fi/api/discount/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.suby.fi/api/discount/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'WELCOME10',
'productIds' => [
'pro_abc123',
'pro_sub456'
],
'discountType' => 'FIXED',
'discountPercent' => 10,
'discountAmountCents' => 500,
'preApply' => false,
'maxUses' => 100,
'expiresAt' => '2026-12-31T23:59:59Z',
'externalRef' => 'almanak_user_42',
'isActive' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Suby-Api-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.suby.fi/api/discount/create"
payload := strings.NewReader("{\n \"name\": \"WELCOME10\",\n \"productIds\": [\n \"pro_abc123\",\n \"pro_sub456\"\n ],\n \"discountType\": \"FIXED\",\n \"discountPercent\": 10,\n \"discountAmountCents\": 500,\n \"preApply\": false,\n \"maxUses\": 100,\n \"expiresAt\": \"2026-12-31T23:59:59Z\",\n \"externalRef\": \"almanak_user_42\",\n \"isActive\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Suby-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.suby.fi/api/discount/create")
.header("X-Suby-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"WELCOME10\",\n \"productIds\": [\n \"pro_abc123\",\n \"pro_sub456\"\n ],\n \"discountType\": \"FIXED\",\n \"discountPercent\": 10,\n \"discountAmountCents\": 500,\n \"preApply\": false,\n \"maxUses\": 100,\n \"expiresAt\": \"2026-12-31T23:59:59Z\",\n \"externalRef\": \"almanak_user_42\",\n \"isActive\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.suby.fi/api/discount/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Suby-Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"WELCOME10\",\n \"productIds\": [\n \"pro_abc123\",\n \"pro_sub456\"\n ],\n \"discountType\": \"FIXED\",\n \"discountPercent\": 10,\n \"discountAmountCents\": 500,\n \"preApply\": false,\n \"maxUses\": 100,\n \"expiresAt\": \"2026-12-31T23:59:59Z\",\n \"externalRef\": \"almanak_user_42\",\n \"isActive\": true\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"id": "dis_abc123",
"name": "WELCOME10",
"discountType": "PERCENT",
"discountPercent": 1000,
"discountAmountCents": null,
"preApply": true,
"expiresAt": "2023-11-07T05:31:56Z",
"maxUses": 123,
"externalRef": "almanak_user_42",
"isActive": true,
"products": [
{
"id": "<string>",
"name": "<string>",
"platform": "WEB"
}
]
}
}{
"success": false,
"error": {
"code": "PRODUCT_NOT_FOUND",
"message": "Product not found"
}
}{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or missing API key"
}
}Authorizations
API key authentication
Body
The discount code customers enter at checkout.
1 - 50"WELCOME10"
Either the literal string "all" (applies to every product you own) or a non-empty
array of product IDs the code is valid for.
all ["pro_abc123", "pro_sub456"]
Whether the discount is a percentage or a fixed cents amount.
PERCENT, FIXED "FIXED"
Percentage off (1–100). Required when discountType is PERCENT, must NOT be set otherwise.
1 <= x <= 10010
Fixed amount off in cents, applied in each target product's currency.
Required when discountType is FIXED, must NOT be set otherwise.
x >= 1500
When true, the discount is applied automatically at checkout without the customer entering the code.
false
Maximum number of times the code can be redeemed. Omit for effectively unlimited.
x >= 1100
Expiration date (must be in the future). Omit for no expiry.
"2026-12-31T23:59:59Z"
Optional. Binds the code to a single account: it is then only accepted on a checkout created
with the exact same externalRef, and refused everywhere else with
DISCOUNT_CODE_EXTERNAL_REF_MISMATCH.
Use this for per-account codes (prepaid credits, upgrade proration) that must not be
transferable between your users. Matching is exact — no case folding, no trimming — and a
checkout created without an externalRef can never redeem a bound code.
Omit for a code any customer can use.
255"almanak_user_42"
Whether the code is active and redeemable.
Was this page helpful?

