Read the milestones
Get invoice details, Create invoice from order, and Update invoice all returnbilling_milestones, oldest first:
id back to change or remove a milestone. Voided milestones aren’t listed.
Change the milestones
Sendbilling_milestones_attributes to Update invoice. Each item changes one milestone:
- Change one: send its
idand the fields you’re changing. - Add one: leave out
id. - Remove one: send its
idwith_destroy: true.
- Milestones must add up to the total. Streamlined checks the milestones as they’d be after your change: the ones you send, plus every one you leave out at its saved amount. Together they must equal the invoice total, or 100% when every milestone is a percentage. Leaving a milestone out keeps it. It doesn’t remove it.
- Issued milestones can’t change. If you change one or send it with
_destroy: true, the request still gets a200and the milestone stays as it was. Its saved amount counts toward the total. - Voided milestones are skipped. They aren’t listed. If you send the
idof one you read before it was voided, Streamlined skips that item and saves the rest of the request. Voided milestones don’t count toward the total. - Send each milestone once. Sending the same
idin two items is refused withduplicate_milestone. - Dates you send can’t be in the past. Only the dates in an item are checked. An item with no
issued_atand nodue_dateisn’t checked, so neither item in the example above is. An item’s due date is itsdue_date, orissued_atplusnet_termsdays when it has nodue_date. Its issue and due dates must be today or later, and no earlier than those of the items before it in the request. Issued milestones keep their dates. - It’s all or nothing. If Streamlined refuses the request, nothing on the invoice changes, including the due date, memo, and PO number.
id can be a number or a string of the same digits. To send a single milestone, you can use one object instead of a list. _destroy removes the milestone when it’s true, "true", "1", or 1, and does nothing when it’s false, "false", "0", or empty.
When milestones are issued
issue_method decides when a milestone is issued:
The API and the AI assistant tools can’t issue a milestone.
When the invoice is paid in full, every milestone not yet issued is issued, without an email. That includes a
SPECIFIED milestone with no issued_at.
due_date is set like this:
- When a milestone is added: a
SPECIFIEDmilestone with anissued_atandnet_termsabove0getsissued_atplusnet_termsdays. Any other milestone keeps thedue_dateyou send, or null if you don’t send one. - When a milestone is changed: it keeps the
due_dateyou send. Nothing is recalculated until it’s issued. - When a milestone is issued: with
net_termsabove0, it becomes the issue date plusnet_termsdays, replacing any date saved before. Withnet_termsof0, it keeps its saveddue_date, or becomes the issue date if there isn’t one.
Errors
When Update invoice refuses a request, it returns422 and changes nothing. Show people error, and branch on code:
Treat any
code you don’t recognize like a 422 without one: show error and don’t retry unchanged.