Record Cost Entry Source Lines
PUT/api/cost-entries/:costEntry/source-lines
Replaces the cost entry's source lines with the given lines and links or creates allocations, all in one transaction. Allocations linked to replaced lines keep existing and are re-linked when they match again.
purchase-orders:writeGrant this scope to your token under Settings → Developer → Personal Access Tokens.
Each line: charge_type (required: product_charge, account_fee, unmatched_reference, rounding, adjustment, other), description (required, ≤500), amount (required, signed, entry currency), basis (required: invoiced = printed on the vendor document; estimated_split = your own split of an invoice charge; computed = e.g. rounding; manual), and optional charge_group (the invoice charge the line belongs to, e.g. "Pallet storage"), external_reference (vendor SKU / code), product_id or product_sku (otherwise a product_charge's external_reference is matched to a product SKU, case-insensitive; no match turns it into unmatched_reference, and an unmatched_reference whose reference does match a product — archived included — becomes a product_charge; recognising a product allocates nothing by itself), quantity, unit, rate, period_start, period_end (Y-m-d, end ≥ start), basis_note (≤500), basis_as_of (ISO 8601 — the snapshot an estimated split was computed from), source_row, metadata (object).
allocation_mode: link_existing (default — link each product line to an existing, unlinked allocation of the same product and amount to the cent, and the same period end when both have one; creates nothing), create (link where possible, then allocate every remaining product line to its product), none (record the lines only).
dry_run: true runs everything and rolls it back, returning what would happen (200). To attach the vendor file, send multipart/form-data to the same path with POST: file (≤20 MB — PDF, images, Word, Excel, CSV, text) and the JSON body as a payload field; the file is stored with the entry (and its bill, when it has one) and each line points at it.
Refused with 422 when the lines total more than the entry amount, or when creating an allocation would exceed what the entry has left.
Authentication: Requires Bearer token (scope purchase-orders:write).
Request
Responses
- 201
- 401
- 403
- 404
- 422
- 429
Created
Response Headers
Unauthenticated — the bearer token is missing, revoked, expired, or malformed. Never retry automatically; fix the credential. See the Errors guide.
Forbidden — the token lacks a required scope, the endpoint is not available to API tokens, or the user behind the token lacks the permission. A human must adjust the token scopes or user permissions; do not retry.
Not found — no record with the given identifier (or the route does not exist). Verify the ID before retrying.
Unprocessable Entity
Response Headers
Rate limited — platform limit is 1,000 requests/min; individual tokens may carry lower limits. Honor the Retry-After header before retrying. See the Rate Limits guide.