- a negotiated rate for one customer
- a change in seat count from a given date
- an extra price that only this customer pays, such as an onboarding fee for three months
- the end of a price, for example when a customer drops an add-on
Prerequisites
- An API key. See API keys.
- A subscription on Standard Billing (
billingVersion: 1). See Billing Versions. - The subscription ID.
Read the intervals
Send a change
All changes go to one endpoint,POST /v0/subscriptions/{id}/intervals. The body has three
lists. Each list is optional, but you must send one operation or more.
addmakes new intervals.editchanges intervals, byid.removedeletes intervals, byid.
edit can change four fields: unitPrice, baseQuantity, quantityTransitions, and endDate.
If you do not send a field, it stays the same. You can send the other fields too, but each one must
be equal to its current value. So you can send an interval from the GET response back as an
edit. Delete its kind field first, because an edit does not accept it. If nothing changes,
the response has "unchanged": true.
If a request times out, do not send an add again. If the first request succeeded, the second
add overlaps the interval that the first one made, and the API refuses it with a 409. Read the
intervals to see the result.
After a change, the API calculates again the invoice lines that are not on an invoice yet. It does
not change an invoice that exists. See The response.
The billing periods of a price
Each date that you send must agree with the billing periods of the price. The periods repeat at thebillingCadence of the price, from the billing anchor of the subscription:
- For most subscriptions, the billing anchor is the start of the subscription.
- If the billing anchor is after the start, the time from the start to the anchor is a partial first period. The full periods repeat from the anchor.
startDate and endDate that you send:
- A date on a period boundary. The API accepts it. Each period bills in full.
- A date inside a period. The API accepts it and splits the period at that date. Each part bills for the part of the period that it covers, measured in time. For example, a monthly fee that ends on 16 April bills 15 days of the 30 days of April.
- A date before the billing anchor. The API refuses it. The start of the subscription is the only exception.
- a metered price whose billable metric does not use
sumorcountaggregation - a metered price with grant discounts (
grantDiscountEnabled) - a price with the
volumemodel or the legacypercentagemodel - a price that is owed in full for each period (
isObligation: true)
Change a price
To give one subscription a different rate, setunitPrice on its interval. Write the rate as a
decimal string, per unit and per period. You can set unitPrice only on a price with the
standard model.
unitPrice to null.
Change a price from a date
The platform fee bills in advance, so the March period is invoiced on 1 March. An edit to the rate of the full interval changes March too, and the API refuses it. To change the rate from 1 April, send these two operations in one request:- Set the
endDateof the interval to 1 April. - Add an interval for the same
priceKeythat starts on 1 April.
priceKey that
is on the plan version, the API takes the price from the plan version, so you do not send
priceId.
Change a quantity
To change the quantity for the full interval, setbaseQuantity. To change it from a date, add
a transition:
quantityTransitions replaces
the full list, so send all the transitions that you want to keep. The same rule about invoiced
periods applies. In the example, a baseQuantity of 5 changes March, so the API refuses it.
Add a price to one subscription
To bill a price that is not on the plan, add an interval with a newpriceKey and the priceId of
a catalog price. The interval is subscription_owned: it belongs to this subscription only.
endDate, or send null.
Obey these rules for a new priceKey:
- Start the key with a lowercase letter or a digit. Use only lowercase letters, digits, hyphens, and underscores. Use 64 characters or fewer.
- Send
unitPricein all cases. If you sendnull, the interval keeps the catalog price that applies on the day that you add it. Later changes to the catalog price do not change it. - Use a catalog price that no other interval of the subscription bills at the same time. Two
intervals with the same
priceIdmust not overlap. - Use a metered price with
billingMode: "arrears"only.
subscription_owned interval with no
endDate stops at that change. An interval with an endDate keeps its dates.
Close a price
To stop a price, set theendDate of its interval:
endDate to null. You can do this only while no period
after the old endDate is invoiced.
To delete an interval, put its id in remove. Do this only for an interval that has no invoiced
period, such as an interval that starts in the future. The API refuses a request that removes all
the intervals of a subscription.
What the API refuses
An invoiced period cannot change
A period is invoiced when its invoice moment is now or in the past:- A price that bills in
advancehas its invoice moment at the start of the period. - A price that bills in
arrearshas its invoice moment at the end of the period. - If a date splits a period, each part has its own invoice moment.
details.periodStart is the first invoiced period of the price. details.change tells you what
the request changed: repriced, requantified, reshaped, or uncovered. To fix the request,
start the change at the end of the last invoiced period, or later.
Other refusals
The response
A successful request returns all the intervals after the change inintervals, and two more
fields:
unchangedistrueif the request changed nothing.lineItemscounts the prices whose invoice lines the API calculated again (created) or deleted (removed).lineItems.syncFailedistrueif the API saves the change but cannot calculate the invoice lines again. The change stays saved, and the API tries again automatically. To try again immediately, send the same request again.
Next steps
- Get Price Intervals and Edit Price Intervals — the API reference
- Editing prices — change a price for all subscribers
- Quantity bounds — bill a contracted minimum or maximum quantity
- Subscriptions — the subscription lifecycle