API REFERENCE

Contracts API

A contract is the agreement that ties a client to a billing arrangement over a date range. It holds no prices of its own. The numbers live on contract lines, which you attach once the contract exists.

Create the agreement

A contract only appears under Billing > Client Contracts once it is assigned to its client, so POST /api/v1/contracts creates both in one step, the same way the contract wizard does. client_id, contract_name, billing_frequency, and start_date are required; a request missing client_id or start_date returns 400. An open-ended contract simply omits end_date. Dates accept a plain YYYY-MM-DD or a full ISO datetime.

The same body can carry the assignment terms the wizard stores — billing_profile_id, renewal settings such as renewal_mode and notice_period_days, and po_required/po_number — and an optional lines array of contract lines to attach. The header, the client assignment, and every line are written in one transaction: if any line is invalid, nothing is created.

curl
curl https://algapsa.com/api/v1/contracts \
  -H "X-API-Key: $ALGA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "cl_3f9a2c",
    "contract_name": "Managed services 2026",
    "start_date": "2026-01-01",
    "billing_frequency": "monthly",
    "lines": [
      { "contract_line_id": "cln_7d10" }
    ]
  }'

Read, update, and delete

GET /api/v1/contracts/{contractId} returns the contract with its client assignments and contract lines. PUT (or PATCH) on the same path edits header fields only: contract_name, contract_description, billing_frequency, status, and is_active. Ownership cannot be changed, so a body that includes client_id is rejected with 400. Assignment dates and terms are edited through the assignment routes below.

DELETE /api/v1/contracts/{contractId} follows the same rules as the app: it returns 204 on success, 409 when invoices already reference the contract, and 422 for a system-managed default contract (which also refuses updates).

Client assignments

The assignment is the record that links a contract to its client and holds the dates and renewal and PO terms. Manage it under /api/v1/contracts/{contractId}/assignments: GET lists it, and GET, PUT, and DELETE on /assignments/{clientContractId} read, change, or remove one. Sending "is_active": true on an update activates a draft assignment and its contract together, like Set to Active in the app. An assignment that invoices reference cannot be deleted (409); set an end_date instead.

Contracts created through earlier versions of the API were saved without an assignment and do not show up in the app. Repair one with POST /api/v1/contracts/{contractId}/assignments and a start_date; the client defaults to the contract's owner. If the contract already has an assignment, the call returns 409 with the existing client_contract_id.

Contract statuses

The API stores six statuses: draft, active, terminated, expired, published, and archived. The “Scheduled” label shown in the MSP app for an active contract whose start_date is still in the future is a display-only derivation; the API never returns a scheduled value. Billing on such a contract begins automatically on its start date.

Attach the lines

Pricing comes from contract lines. Bind one to the agreement with POST /api/v1/contracts/{contractId}/contract-lines and remove it with DELETE /api/v1/contracts/{contractId}/contract-lines/{contractLineId}. The lines themselves are defined and edited through the Contract Lines API; this endpoint only controls which ones belong to this contract.

Endpoints

Every endpoint links through to its full parameters, request and response schemas, and code samples.

GET/api/v1/contractsAlgaPSAList contractsPOST/api/v1/contractsAlgaPSACreate contractPOST/api/v1/contracts/{contractId}/contract-linesAlgaPSAAttach contract lineDELETE/api/v1/contracts/{contractId}/contract-lines/{contractLineId}AlgaPSADetach contract line