curl --request POST \
--url https://api.beta.suby.fi/v3/discount-codes \
--header 'Content-Type: application/json' \
--header 'X-Suby-Api-Key: <api-key>' \
--data '
{
"name": "NOEL2026",
"discountType": "PERCENTAGE",
"discountPercent": 50,
"discountAmountCents": "500",
"currency": "<string>",
"productIds": [],
"maxUses": 2,
"expiresAt": "2023-11-07T05:31:56Z",
"preApply": false
}
'import requests
url = "https://api.beta.suby.fi/v3/discount-codes"
payload = {
"name": "NOEL2026",
"discountType": "PERCENTAGE",
"discountPercent": 50,
"discountAmountCents": "500",
"currency": "<string>",
"productIds": [],
"maxUses": 2,
"expiresAt": "2023-11-07T05:31:56Z",
"preApply": False
}
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: 'NOEL2026',
discountType: 'PERCENTAGE',
discountPercent: 50,
discountAmountCents: '500',
currency: '<string>',
productIds: [],
maxUses: 2,
expiresAt: '2023-11-07T05:31:56Z',
preApply: false
})
};
fetch('https://api.beta.suby.fi/v3/discount-codes', 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.beta.suby.fi/v3/discount-codes",
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' => 'NOEL2026',
'discountType' => 'PERCENTAGE',
'discountPercent' => 50,
'discountAmountCents' => '500',
'currency' => '<string>',
'productIds' => [
],
'maxUses' => 2,
'expiresAt' => '2023-11-07T05:31:56Z',
'preApply' => false
]),
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.beta.suby.fi/v3/discount-codes"
payload := strings.NewReader("{\n \"name\": \"NOEL2026\",\n \"discountType\": \"PERCENTAGE\",\n \"discountPercent\": 50,\n \"discountAmountCents\": \"500\",\n \"currency\": \"<string>\",\n \"productIds\": [],\n \"maxUses\": 2,\n \"expiresAt\": \"2023-11-07T05:31:56Z\",\n \"preApply\": false\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.beta.suby.fi/v3/discount-codes")
.header("X-Suby-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"NOEL2026\",\n \"discountType\": \"PERCENTAGE\",\n \"discountPercent\": 50,\n \"discountAmountCents\": \"500\",\n \"currency\": \"<string>\",\n \"productIds\": [],\n \"maxUses\": 2,\n \"expiresAt\": \"2023-11-07T05:31:56Z\",\n \"preApply\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.beta.suby.fi/v3/discount-codes")
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\": \"NOEL2026\",\n \"discountType\": \"PERCENTAGE\",\n \"discountPercent\": 50,\n \"discountAmountCents\": \"500\",\n \"currency\": \"<string>\",\n \"productIds\": [],\n \"maxUses\": 2,\n \"expiresAt\": \"2023-11-07T05:31:56Z\",\n \"preApply\": false\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"id": "disc_abc123",
"name": "NOEL2026",
"discountType": "PERCENTAGE",
"discountPercent": 50,
"discountAmountCents": "500",
"currency": "<string>",
"productIds": [
"pro_abc123"
],
"maxUses": 123,
"usedCount": 123,
"expiresAt": "2023-11-07T05:31:56Z",
"isActive": true,
"preApply": true,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"message": "<string>"
}{
"success": false,
"error": "UNAUTHORIZED",
"message": "Invalid or missing API key"
}{
"success": false,
"error": "NOT_FOUND",
"message": "Resource not found",
"data": {
"fieldErrors": [
{
"field": "<string>",
"message": "<string>"
}
]
}
}Create a discount code
Mint a promo code. The code is redeemed at checkout · passed on the session
as discountCode, applied on its own when preApply is set, or typed by
the payer on the hosted page · and is re-validated and re-priced
server-side there. A payer can never set an amount.
curl --request POST \
--url https://api.beta.suby.fi/v3/discount-codes \
--header 'Content-Type: application/json' \
--header 'X-Suby-Api-Key: <api-key>' \
--data '
{
"name": "NOEL2026",
"discountType": "PERCENTAGE",
"discountPercent": 50,
"discountAmountCents": "500",
"currency": "<string>",
"productIds": [],
"maxUses": 2,
"expiresAt": "2023-11-07T05:31:56Z",
"preApply": false
}
'import requests
url = "https://api.beta.suby.fi/v3/discount-codes"
payload = {
"name": "NOEL2026",
"discountType": "PERCENTAGE",
"discountPercent": 50,
"discountAmountCents": "500",
"currency": "<string>",
"productIds": [],
"maxUses": 2,
"expiresAt": "2023-11-07T05:31:56Z",
"preApply": False
}
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: 'NOEL2026',
discountType: 'PERCENTAGE',
discountPercent: 50,
discountAmountCents: '500',
currency: '<string>',
productIds: [],
maxUses: 2,
expiresAt: '2023-11-07T05:31:56Z',
preApply: false
})
};
fetch('https://api.beta.suby.fi/v3/discount-codes', 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.beta.suby.fi/v3/discount-codes",
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' => 'NOEL2026',
'discountType' => 'PERCENTAGE',
'discountPercent' => 50,
'discountAmountCents' => '500',
'currency' => '<string>',
'productIds' => [
],
'maxUses' => 2,
'expiresAt' => '2023-11-07T05:31:56Z',
'preApply' => false
]),
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.beta.suby.fi/v3/discount-codes"
payload := strings.NewReader("{\n \"name\": \"NOEL2026\",\n \"discountType\": \"PERCENTAGE\",\n \"discountPercent\": 50,\n \"discountAmountCents\": \"500\",\n \"currency\": \"<string>\",\n \"productIds\": [],\n \"maxUses\": 2,\n \"expiresAt\": \"2023-11-07T05:31:56Z\",\n \"preApply\": false\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.beta.suby.fi/v3/discount-codes")
.header("X-Suby-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"NOEL2026\",\n \"discountType\": \"PERCENTAGE\",\n \"discountPercent\": 50,\n \"discountAmountCents\": \"500\",\n \"currency\": \"<string>\",\n \"productIds\": [],\n \"maxUses\": 2,\n \"expiresAt\": \"2023-11-07T05:31:56Z\",\n \"preApply\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.beta.suby.fi/v3/discount-codes")
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\": \"NOEL2026\",\n \"discountType\": \"PERCENTAGE\",\n \"discountPercent\": 50,\n \"discountAmountCents\": \"500\",\n \"currency\": \"<string>\",\n \"productIds\": [],\n \"maxUses\": 2,\n \"expiresAt\": \"2023-11-07T05:31:56Z\",\n \"preApply\": false\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"id": "disc_abc123",
"name": "NOEL2026",
"discountType": "PERCENTAGE",
"discountPercent": 50,
"discountAmountCents": "500",
"currency": "<string>",
"productIds": [
"pro_abc123"
],
"maxUses": 123,
"usedCount": 123,
"expiresAt": "2023-11-07T05:31:56Z",
"isActive": true,
"preApply": true,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"message": "<string>"
}{
"success": false,
"error": "UNAUTHORIZED",
"message": "Invalid or missing API key"
}{
"success": false,
"error": "NOT_FOUND",
"message": "Resource not found",
"data": {
"fieldErrors": [
{
"field": "<string>",
"message": "<string>"
}
]
}
}Authorizations
Secret API key. sk_live_… (production) or sk_sandbox_… (sandbox).
Headers
Optional key (≤255 chars, e.g. a UUID v4) that makes this POST safe to retry: the first request executes and its response is cached for 24h; a retry with the SAME key replays that response instead of re-executing (no duplicate payment/subscription). A reused key with a different request → 422 IDEMPOTENCY_KEY_CONFLICT; a retry while the first is still in flight → 409. See the Idempotency guide.
255"5f3b9c2e-1a4d-4f2b-9c31-7e2a1b6d8c04"
Body
Only the field matching discountType is stored; the other is cleared, so a code can never carry two contradictory discounts.
The code you hand out. Unique per account and environment.
2 - 40^[A-Z0-9][A-Z0-9_-]*$"NOEL2026"
PERCENTAGE, FIXED Required when discountType=PERCENTAGE.
1 <= x <= 99Required when discountType=FIXED. Minor units as a string of digits.
^[1-9]\\d*$"500"
Required when discountType=FIXED.
^[A-Z]{3}$Eligible products. Leave empty to apply to every product.
Global redemption cap. Null = unlimited. Counts settled redemptions plus checkouts still in flight, so the last use cannot be handed to two buyers at once; an abandoned attempt releases its slot on its own expiry.
x >= 1Apply this code on the hosted checkout with no payer input, on every order it covers. A code carried by the session (discountCode on POST /v3/checkout/sessions) wins over it. The payer sees the discount already deducted and can still remove it. A pre-applied code that no longer redeems is silently not applied · the page shows the full price rather than an error the payer did not cause.
Was this page helpful?

