cURL
curl --request POST 'https://api.integrateledger.com/v1/customers/auto-top-up?customerId=user_123' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"autoTopUp":{"enabled":true,"thresholdCredits":100,"addOnId":"credits_500","maxPerPeriod":3}}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.setCustomerAutoTopUp({ customerId: "user_123", body: { autoTopUp: { enabled: true, thresholdCredits: 100, addOnId: "credits_500", maxPerPeriod: 3 } } });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.set_customer_auto_top_up(customer_id="user_123", auto_top_up={"enabled": True, "thresholdCredits": 100, "addOnId": "credits_500", "maxPerPeriod": 3}){
"customerId": "<string>",
"autoTopUp": {
"source": "customer",
"enabled": true,
"thresholdCredits": 123,
"addOnId": "<string>",
"amountCents": 123,
"credits": 123,
"maxPerPeriod": 123,
"maxAmountCentsPerPeriod": 123
},
"suspended": true,
"coolingDownUntil": "2023-11-07T05:31:56Z",
"recent": [
{
"id": 123,
"trigger": "auto",
"status": "pending",
"failureReason": "<string>",
"credits": 123,
"amountCents": 123,
"stripeInvoiceId": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"completedAt": "2023-11-07T05:31:56Z"
}
]
}{
"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."
}Customers
Set a customer's auto top-up
Buy credits with the customer’s saved card when their balance runs low.
POST
/
v1
/
customers
/
auto-top-up
cURL
curl --request POST 'https://api.integrateledger.com/v1/customers/auto-top-up?customerId=user_123' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"autoTopUp":{"enabled":true,"thresholdCredits":100,"addOnId":"credits_500","maxPerPeriod":3}}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.setCustomerAutoTopUp({ customerId: "user_123", body: { autoTopUp: { enabled: true, thresholdCredits: 100, addOnId: "credits_500", maxPerPeriod: 3 } } });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.set_customer_auto_top_up(customer_id="user_123", auto_top_up={"enabled": True, "thresholdCredits": 100, "addOnId": "credits_500", "maxPerPeriod": 3}){
"customerId": "<string>",
"autoTopUp": {
"source": "customer",
"enabled": true,
"thresholdCredits": 123,
"addOnId": "<string>",
"amountCents": 123,
"credits": 123,
"maxPerPeriod": 123,
"maxAmountCentsPerPeriod": 123
},
"suspended": true,
"coolingDownUntil": "2023-11-07T05:31:56Z",
"recent": [
{
"id": 123,
"trigger": "auto",
"status": "pending",
"failureReason": "<string>",
"credits": 123,
"amountCents": 123,
"stripeInvoiceId": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"completedAt": "2023-11-07T05:31:56Z"
}
]
}{
"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."
}Saves the customer’s own auto top-up, which replaces their plan’s default whole.
enabled: false turns the plan’s default off; autoTopUp: null clears the customer’s setting so the plan’s applies again. Saving restarts a cooldown or suspension after failures.
It buys a credit pack (addOnId) or an amount (amountCents, within the catalog’s topUps), one of the two: otherwise 400 invalid_auto_top_up, add_on_not_found, top_ups_not_configured or top_up_amount_out_of_range.
The response is what Get a customer’s auto top-up returns. Needs the Customers permission.Authorizations
Query Parameters
Body
application/json
Response
Saved; the auto top-up that now applies