Coupons
Create Coupon
Create a new discount coupon
POST
/
v1
/
coupons
Create a coupon
curl --request POST \
--url https://billing.example.com/v1/coupons \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"discount_value": 123,
"duration_months": 123
}
'import requests
url = "https://billing.example.com/v1/coupons"
payload = {
"code": "<string>",
"discount_value": 123,
"duration_months": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: '<string>', discount_value: 123, duration_months: 123})
};
fetch('https://billing.example.com/v1/coupons', 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://billing.example.com/v1/coupons",
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([
'code' => '<string>',
'discount_value' => 123,
'duration_months' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://billing.example.com/v1/coupons"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"discount_value\": 123,\n \"duration_months\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://billing.example.com/v1/coupons")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"discount_value\": 123,\n \"duration_months\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/coupons")
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 \"code\": \"<string>\",\n \"discount_value\": 123,\n \"duration_months\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"tenant_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"code": "<string>",
"discount_type": "percent",
"discount_value": 123,
"duration": "forever",
"duration_months": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Unique coupon code |
discount_type | string | Yes | percent or amount |
discount_value | number | Yes | Percent (for percent) or the amount in minor currency units (for amount) |
currency | string | No | Three-letter ISO currency code (required for the amount discount type) |
duration | string | Yes | once, repeating, or forever |
duration_in_months | integer | No | Number of months the coupon applies (required when duration is repeating) |
max_redemptions | integer | No | Maximum number of times this coupon can be redeemed |
Example Request
curl -X POST https://api.recurso.dev/v1/coupons \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "SUMMER25",
"discount_type": "percent",
"discount_value": 25,
"duration": "repeating",
"duration_in_months": 3,
"max_redemptions": 500
}'
Response
{
"id": "cpn_s25_3mo",
"object": "coupon",
"code": "SUMMER25",
"discount_type": "percent",
"discount_value": 25,
"currency": null,
"duration": "repeating",
"duration_in_months": 3,
"max_redemptions": 500,
"times_redeemed": 0,
"active": true,
"created_at": "2024-04-01T09:00:00Z"
}
Errors
| Status | Code | When | Fix |
|---|---|---|---|
400 | validation_failed | Missing/invalid fields: code, discount_type, positive discount_value, and duration are required; discount_type must be percent or amount, duration one of forever, once, repeating | Correct the payload — the wire values are percent/amount, not percentage/fixed |
400 | validation_failed | A percent coupon with discount_value above 100 | A discount can’t exceed 100% — cap the value at 100 |
401 | unauthorized | Missing or invalid API key / session | Send Authorization: Bearer $API_KEY |
500 | internal_error | Persisting the coupon failed | Retry; contact support if it persists |
Authorizations
Tenant API key obtained from POST /auth/register or POST /v1/developer/keys.
Body
application/json
Available options:
percent, amount Percentage (0-100) when discount_type is percent, otherwise amount in the lowest currency unit.
Available options:
forever, once, repeating Required when duration is repeating.
Response
Coupon created.
⌘I
Create a coupon
curl --request POST \
--url https://billing.example.com/v1/coupons \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"discount_value": 123,
"duration_months": 123
}
'import requests
url = "https://billing.example.com/v1/coupons"
payload = {
"code": "<string>",
"discount_value": 123,
"duration_months": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: '<string>', discount_value: 123, duration_months: 123})
};
fetch('https://billing.example.com/v1/coupons', 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://billing.example.com/v1/coupons",
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([
'code' => '<string>',
'discount_value' => 123,
'duration_months' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://billing.example.com/v1/coupons"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"discount_value\": 123,\n \"duration_months\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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://billing.example.com/v1/coupons")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"discount_value\": 123,\n \"duration_months\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/coupons")
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 \"code\": \"<string>\",\n \"discount_value\": 123,\n \"duration_months\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"tenant_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"code": "<string>",
"discount_type": "percent",
"discount_value": 123,
"duration": "forever",
"duration_months": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}