cURL
curl --request POST 'https://api.integrateledger.com/v1/rewards' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"id":"launch20","name":"Launch: 20% off for 3 months","coupon":{"percentOff":20,"duration":"repeating","durationMonths":3,"planIds":["pro"]},"promotionCodes":[{"code":"LAUNCH20"}]}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.writeReward({ id: "launch20", name: "Launch: 20% off for 3 months", coupon: { percentOff: 20, duration: "repeating", durationMonths: 3, planIds: ["pro"] }, promotionCodes: [{ code: "LAUNCH20" }] });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.write_reward({"id": "launch20", "name": "Launch: 20% off for 3 months", "coupon": {"percentOff": 20, "duration": "repeating", "durationMonths": 3, "planIds": ["pro"]}, "promotionCodes": [{"code": "LAUNCH20"}]}){
"item": {
"id": "<string>",
"name": "<string>",
"kind": "coupon",
"coupon": {
"percentOff": 123,
"amountOffCents": 123,
"currency": "<string>",
"duration": "once",
"durationMonths": 123,
"planIds": [
"<string>"
]
},
"grant": {
"items": [
{
"featureId": "<string>",
"amount": 123,
"expiresAfter": {
"days": 123,
"months": 123
}
}
]
},
"maxRedemptions": 123,
"timesRedeemed": 123,
"redeemBy": "<string>",
"oncePerCustomer": true,
"archived": true,
"stripeSyncStatus": "pending",
"stripeSyncError": "<string>",
"promotionCodes": [
{
"code": "<string>",
"source": "catalog",
"active": true,
"customerId": "<string>",
"maxRedemptions": 123,
"timesRedeemed": 123,
"expiresAt": "<string>",
"firstTimeOnly": true
}
]
},
"changed": true
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "insufficient_permissions",
"requiredScope": "customers:read",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "payload_too_large",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "rate_limited",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}Rewards
Create or update a reward
Create a coupon reward, or change one, with its promotion codes.
POST
/
v1
/
rewards
cURL
curl --request POST 'https://api.integrateledger.com/v1/rewards' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"id":"launch20","name":"Launch: 20% off for 3 months","coupon":{"percentOff":20,"duration":"repeating","durationMonths":3,"planIds":["pro"]},"promotionCodes":[{"code":"LAUNCH20"}]}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.writeReward({ id: "launch20", name: "Launch: 20% off for 3 months", coupon: { percentOff: 20, duration: "repeating", durationMonths: 3, planIds: ["pro"] }, promotionCodes: [{ code: "LAUNCH20" }] });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.write_reward({"id": "launch20", "name": "Launch: 20% off for 3 months", "coupon": {"percentOff": 20, "duration": "repeating", "durationMonths": 3, "planIds": ["pro"]}, "promotionCodes": [{"code": "LAUNCH20"}]}){
"item": {
"id": "<string>",
"name": "<string>",
"kind": "coupon",
"coupon": {
"percentOff": 123,
"amountOffCents": 123,
"currency": "<string>",
"duration": "once",
"durationMonths": 123,
"planIds": [
"<string>"
]
},
"grant": {
"items": [
{
"featureId": "<string>",
"amount": 123,
"expiresAfter": {
"days": 123,
"months": 123
}
}
]
},
"maxRedemptions": 123,
"timesRedeemed": 123,
"redeemBy": "<string>",
"oncePerCustomer": true,
"archived": true,
"stripeSyncStatus": "pending",
"stripeSyncError": "<string>",
"promotionCodes": [
{
"code": "<string>",
"source": "catalog",
"active": true,
"customerId": "<string>",
"maxRedemptions": 123,
"timesRedeemed": 123,
"expiresAt": "<string>",
"firstTimeOnly": true
}
]
},
"changed": true
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "insufficient_permissions",
"requiredScope": "customers:read",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "payload_too_large",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "rate_limited",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}Takes one reward in the catalog’s shape (see Discounts and promotion codes). A coupon is a percentage (
percentOff) or a fixed amount in cents (amountOffCents) off, once, repeating for durationMonths, or forever, on the paid plans planIds names (every version of each), or every paid plan with null. It never discounts usage or credit packs. promotionCodes are the reward’s catalog codes: ones left out are deactivated, and codes added with Add a promotion code are kept.
Changing the amount, duration or plans makes a new Stripe coupon; customers who already have the discount keep its terms, and every active code moves to the new coupon with its remaining uses. An unknown or free plan returns 400 invalid_reward, and a code already active on another reward 409 promotion_code_taken. Needs the Catalog permission at Write.Authorizations
Body
application/json