contracts:read permission to read contracts, contracts:write to create and change them, and contracts:approve to approve or reject them. See API keys for how to send the key.
How a contract moves
A contract starts as a draft. You can change a draft as often as you like. When someone approves it, it becomes the contract in force. After that, a change does not touch the contract in force. It waits beside it as a pending change until someone decides on it.
After approval, the status follows the dates on the customer’s clock. If the customer has a test clock, the test-clock time decides.
Create a contract
CallPOST /v0/contracts. Both values of autoApprove are required, and there is no default. Set autoApprove.contract to false to review the contract first.
201. The contract is a draft, and each line has an id that starts with ctrl_.
startDate, endDate and invoiceOffsetDays on each line. See the Create API reference for all fields.
Send the same deal twice
When you send anexternalReference, a create first looks for the contract that record already has. If there is one, the response is that contract with status 200, and nothing is created. You can send a CRM deal again after a timeout without making a second contract. If the externalReference already has a contract for another customer, the create fails with a 409 and CONTRACT_REFERENCE_CUSTOMER_MISMATCH, and nothing is written.
Line entries
Every entry inlines is a new line. You can write an entry in two ways when you create a contract.
A line for an item is a fee line when the item has no billable metric. It is a metered line when the item has one. When the item has several billable metrics, name the one to bill in
billableMetricId. If you do not, the request fails with a 400 and CONTRACT_LINE_METRIC_AMBIGUOUS. The error lists the metrics.
A line from a plan version copies the price, cadence, payment term and display fields. It does not follow later changes to the plan.
copiedFromPriceId set to the price it copied.
Change a draft
CallPATCH /v0/contracts/{id}. Send the updatedAt that you read as basedOnUpdatedAt. If the draft changed after you read it, the request fails with a 409 and CONTRACT_CHANGED, so two people cannot overwrite each other.
When you send lines, they are the complete set of lines. An entry with an id keeps that line and changes the fields you send. An entry without an id adds a line. A line that you leave out is removed. If you do not send lines, the lines stay as they are.
updatedAt. The licence line now has "quantity": "2", and the second line is as it was.
The customer and the currency are fixed when you create the contract. Send the same value or leave them out. A different value fails with a 400 and CONTRACT_FIELD_FIXED.
Check a draft before you approve it
Every response that holds a draft or a pending change has two lists,validation and conflicts.
validation lists the reasons you cannot approve the contract yet. This example is a line that starts before the contract term:
conflicts lists lines that share an item or a billable metric with a line of another live contract of the same customer. A conflict is a warning. It never stops an approval.
Preview the invoices
CallGET /v0/contracts/{id}/projected to see the invoices the contract would produce. It writes nothing, so you can call it on a draft as often as you like. Use limit and offset to page through the invoices.
unitPrice. It has no quantity or subtotal until Paygentic measures the usage. When a pending change waits, each line shows the amounts of the change from its next billing moment. Before that moment, the line shows the amounts in force. Paygentic reads the dates on the customer’s clock, which is its test clock when it has one. A rejected contract has no invoices.
For all fields, see the Projected invoices API reference.
Approve or reject
CallPOST /v0/contracts/{id}/decision with approve or reject. This needs the contracts:approve permission. Send the updatedAt of the version you read as basedOnUpdatedAt.
status is now scheduled, because contractStart is in the future. decidedAt and decidedByPrincipalId show when and by whom. Paygentic has written every invoice line of the whole term in one transaction.
To reject, send reason (up to 200 characters) and text (up to 2000 characters). An approval does not take them.
rejected, and rejectReason and rejectText hold your words. A rejected contract cannot change again.
If the contract has validation errors, an approval fails with a 409 and CONTRACT_INVALID. The body lists the errors in details.errors, and the contract stays as it was.
Approve on create
SetautoApprove.contract to true to approve a contract in the request that writes it. This is useful for a contract you import from a system that already approved it. The request needs the contracts:approve permission, and it fails with a 403 without it.
If the contract is valid, Paygentic approves it, and its status follows its dates: scheduled before contractStart, active after it. If it is not valid, the contract stays a draft, and validation lists the errors. Someone can fix it and approve it later.
A PATCH that leaves autoApprove.contract set to true needs contracts:approve too.
autoApprove.invoices is a separate choice. It sets whether Paygentic approves the contract’s invoices when it collects them.
Change an approved contract
The firstPATCH of an approved contract opens a pending change. It is a copy of the contract in force with your fields applied. Later PATCH requests edit that change. Send the change’s updatedAt as basedOnUpdatedAt.
"quantity": "2". The new quantity is in pendingChange, which has the same fields as the contract and its own updatedAt.
PATCH without basedOnUpdatedAt while a change waits, the request fails with a 409 and CONTRACT_PENDING_CHANGE_EXISTS. Read the contract and send the updatedAt of the change.
To discard a pending change, reject it with the change’s updatedAt. The contract in force stays as it was, and pendingChange is null again.
Approving a pending change on a contract that is already approved is not available yet. It fails with a 409 and CONTRACT_RETILE_NOT_AVAILABLE. While a change waits, validation lists this code.
List contracts
CallGET /v0/contracts. The newest contract is first. Use these filters, and limit and offset to page.
data and pagination. Read one contract with GET /v0/contracts/{id}.
Errors
A failed request has the error body that every API call has. Checkcode in your code. A schema failure is the one exception: see the note under the table.
A schema failure has
"error": "validation_error", a message that names the field, and a requestId. It has no code and no errors array, so test error and read message for it.
This is the body of a stale write:
Related pages
- Projected invoices: preview the invoices of a subscription
- Invoices: how Paygentic issues and collects invoices
- Errors: the shape of an error response