New Introducing inventory in LightInventory in Light Read the announcementRead more

API/Examples

Change a live contract

Open an edit on an active contract, change it and publish it, with what an edit can and cannot change and what a reset does.

Section
Examples
Reading
3 min read
On this page
  1. 01What an edit can change
  2. 02What an edit cannot change
  3. 03Reset
  4. 04Retries

A contract records what a customer buys, from when, and how often it is billed. Each contract line is a product with its own quantity, price and billing dates. A contract is created as a DRAFT; publishing it makes it ACTIVE, and Light then invoices it on its schedule.

An ACTIVE contract is changed through an edit. Opening and publishing an edit do not change the contract's state, and invoices Light generates while the edit is open follow the published version.

  1. POST /v1/contracts/{contractId}/begin-edit opens the edit. hasWorkingVersion becomes true. A contract has one open edit at a time: a second begin-edit, or a begin-edit on a contract that is not ACTIVE, returns CONTRACT_CANNOT_BE_MODIFIED.
  2. Make the changes with PATCH /v1/contracts/{contractId}. While the edit is open, GET /v1/contracts/{contractId} returns the edit's fields and lines.
  3. POST /v1/contracts/{contractId}/publish applies the edit. The contract's state does not change and hasWorkingVersion goes back to false.
  4. GET /v1/contracts/{contractId} returns the published contract.

POST /v1/contracts/{contractId}/cancel-edit discards the edit instead and restores the published version.

What an edit can change

  • On the contract: startDate, endDate, renewalDate, estimatedAmount, netTerms, invoiceLeadDays, payeeBankAccountId, description and customProperties. The other fields of the update request, such as currency, companyEntityId, invoiceTemplateId, paymentType, billingStart or areLinesWithTax, return CONTRACT_CANNOT_BE_MODIFIED.

What an edit cannot change

  • A line that was already published, apart from its customProperties. A change to any other field of that line, such as quantity, priceOverwrite, discount or productId, and deleting the line return CONTRACT_LINE_CANNOT_BE_MODIFIED. A new billingEnd is the exception: the update may accept it, and publish can then return CONTRACT_AMENDMENT_REQUIRED. The edit stays open after that refused publish; cancel it to discard the change.
  • An invoiced period. A new startDate or endDate that changes an invoiced period is refused at publish with one of CONTRACT_LINE_WOULD_MODIFY_INVOICED_PERIODS, CONTRACT_START_DATE_WOULD_MODIFY_INVOICED_PERIODS (when the new startDate alone causes it) or CONTRACT_PART_PERIOD_ALREADY_INVOICED (when, on a prorated contract, the edit would bill more days of a part period whose invoice is no longer a draft). The exception is a change on a prorated contract that only adds days to a period whose invoice is still a draft: it publishes and updates that draft.

Publishing an edit in which no change was made returns CONTRACT_CANNOT_BE_PUBLISHED.

Reset

POST /v1/contracts/{contractId}/reset takes an ACTIVE contract back to DRAFT. It:

  • archives the draft invoices the contract's schedule created;
  • reverses the contract's posted deferred revenue entries and archives its draft ones;
  • unlinks every invoice from the contract, posted ones included;
  • clears the agreed unit price of every line, so a line priced from the product catalog is published again at the product's current price.

Publishing the contract again is a first publish: it creates draft invoices for the periods of the contract's schedule up to today, including periods the customer was already billed for.

Lowering the quantity of a published line is not possible in an edit, so today it needs a reset, with these effects.

Retries

Every call above that changes the contract accepts an X-Idempotency-Key header. A retry with the same key returns the first result instead of running the call again. See Idempotency.