curl https://api.integrateledger.com/v1/billing/quantities \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H "Idempotency-Key: raise-user_123-1" \
-H "Content-Type: application/json" \
-d '{"customerId": "user_123", "planId": "pro", "quantities": [{"featureId": "credits", "quantity": 10000}]}'
{
"itemChangeId": 123,
"status": "applied",
"paymentUrl": "<string>",
"quantities": [
{
"featureId": "credits",
"quantity": 10000,
"pendingQuantity": null
}
]
}{
"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": "<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": "<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."
}{
"error": "internal_error",
"request_id": "<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."
}{
"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>"
}
]
}Billing
Change a prepaid quantity
Raise or lower how much of a prepaid feature the customer buys each period.
POST
/
v1
/
billing
/
quantities
curl https://api.integrateledger.com/v1/billing/quantities \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H "Idempotency-Key: raise-user_123-1" \
-H "Content-Type: application/json" \
-d '{"customerId": "user_123", "planId": "pro", "quantities": [{"featureId": "credits", "quantity": 10000}]}'
{
"itemChangeId": 123,
"status": "applied",
"paymentUrl": "<string>",
"quantities": [
{
"featureId": "credits",
"quantity": 10000,
"pendingQuantity": null
}
]
}{
"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": "<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": "<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."
}{
"error": "internal_error",
"request_id": "<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."
}{
"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>"
}
]
}Sets a new period total for one prepaid feature of the customer’s plan (
Needs the Billing permission.
"credits" for its credit pool), the included amount counted. Send an Idempotency-Key that identifies this one change, and reuse it on every retry.
- A raise is a prorated change on the customer’s Stripe bill: one invoice with Stripe’s credit for the old packs and charge for the new ones, to the period end, charged to the saved card. Once it’s paid, the customer holds the new quantity and is granted the extra units prorated by the time left in the period, rounded down. The next renewal bills and grants the new quantity in full.
- The same quantity changes nothing:
{ itemChangeId: null, status: "unchanged" }. - A decrease waits for the renewal:
{ status: "scheduled" }, with the new total inpendingQuantity. Nothing is refunded and this period keeps its packs and grant; the renewal bills the lower packs and grants the lower quantity. A later change replaces it: another decrease, or the held quantity again to drop it. A raise while one waits is409 subscription_change_pending.
400 invalid_request at quantities.N.quantity), and at most maxQuantity (400 max_purchase_exceeded). One feature changes per request. The customer must hold the plan on an active paid bill (409 plan_not_held), with no other change pending on it (409 subscription_change_pending). An entity’s own plan sells no prepaid units, so entityId is 400 invalid_request.
status | Meaning |
|---|---|
applied | Paid and granted; quantities holds the new total. |
pending_payment | Send the customer to paymentUrl, Stripe’s hosted invoice page. |
processing | Stripe hasn’t settled it. Retry with the same key. |
closed | Stripe voided the invoice. The old quantity stays. |
scheduled | A decrease, applied at the renewal. |
unchanged | The quantities asked for are the ones held. |
curl https://api.integrateledger.com/v1/billing/quantities \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H "Idempotency-Key: raise-user_123-1" \
-H "Content-Type: application/json" \
-d '{"customerId": "user_123", "planId": "pro", "quantities": [{"featureId": "credits", "quantity": 10000}]}'
Authorizations
Headers
Body
application/json
Response
The change and the quantities the customer holds. A raise is charged now, prorated (Stripe's credit for the old packs and charge for the new), and grants the extra units prorated by the time left in the period; a decrease is scheduled for the renewal, with no refund and this period untouched; the same quantity changes nothing (unchanged).
applied: paid and granted. pending_payment: the card needs the customer (open paymentUrl). processing: Stripe hasn't settled it; retry with the same key. closed: Stripe voided it. scheduled: a decrease, billed and granted from the renewal (pendingQuantity until then). unchanged: the quantities asked for are the ones held.
Available options:
applied, pending_payment, processing, closed, scheduled, unchanged