Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Ramp outbound draft-bill push — enabled + live-verified
Date: 2026-09-11
Branch: feat/feat-ramp (worktree brisbane)
Sandbox: demo-api.ramp.com, client_credentials app ramp_id_nzJ0… (the local
Carbon Development company's stored Ramp connection; metadata.credentials.environment = "sandbox", secret resolved from Vault). Scopes were granted 2026-08-28, so the
bills:write / vendors:read / accounting:read calls below all succeed.
What changed
Removed the RAMP_DRAFT_BILL_CONTRACT_VERIFIED release gate and shipped the outbound
Carbon→Ramp bill push as draft-only (per Brad's decision: "draft only, never submit
… get rid of [the gate] once we verify").
pushInvoiceDraftBill(packages/ee/src/ramp/lib/spend.ts) creates a coded DRAFT bill and links("bill", invoice.id, "ramp", <draft id>). It does not submit.- Accounts come from the POSTED journal, not the invoice line.
pushInvoiceDraftBillreads the invoice's posted "Purchase Invoice" journal vialoadBillCostingLines+toTransactionCurrencyLines— the same authoritative path QBO/Xero/Rillet bill syncers use.purchaseInvoiceLine.accountIdis null for item/part lines (posting resolves inventory / GR-IR / variance / tax accounts), so reading the line would leave item bills uncoded. The costing line'saccountIdIS theaccount.idpushed to Ramp — no translation. Cost center is the journal-line dimension whosevalueIdis a pushedcostCenter.id. - Per-line coding via
buildLineCodingSelections(lib/coding.ts): GL account →{ field_external_id: "Category", field_option_external_id: account.id }; cost center →{ field_external_id: "carbon-cost-center", field_option_external_id: costCenter.id }. A line coded to an account/cost-center Carbon has NOT pushed degrades to uncoded (never 422s the whole bill). If the invoice has no posted journal (accounting was disabled at post time),loadBillCostingLinesthrowsUNMAPPED_ACCOUNTS→ that invoice's push fails and its cursor is retained for retry. remote_id: invoice.idis the echo guard AND bill-match key (the inboundramp-billsstep dedupes on it). Do NOT sendenable_accounting_sync: false— Ramp 422s "enable_accounting_sync cannot be False if remote_id is provided" (caught by the live/teston 2026-09-11; unit tests mocking the client never would have). A draft isn't in Ramp's/billsfeed, so it can't echo before submission anyway.- The outbound job loads the pushed account/cost-center id sets from
externalIntegrationMapping(entityTypeaccount/costCenter) and handsctx.db(Kysely) topushInvoiceDraftBill, which reads the posted journal itself. The oldloadRampPurchaseInvoiceLinesreader was removed (it read the wrong, item-nullpurchaseInvoiceLine.accountId). - Removed archive-on-settlement for bills (drafts are undeletable — see below) and the
now-dead
archiveRampBillForInvoice. PO push + PO archive are untouched.
Live sandbox verification (the contract)
Resolved from the OpenAPI spec (docs.ramp.com/openapi/developer-api.json) AND exercised
live:
- Create coded draft — 201.
POST /bills/draftswithline_items[].accounting_field_selections: [{ field_external_id, field_option_external_id }]. Read-back (GET /bills/drafts/{id}) confirmed the line coded to accountacct_7Dar1tc6okPYA4EahHMezh→ "Travel & Entertainment" (code 6090), and (2nd probe) a cost-center selection coded todag0l963i0gg2a8f2vog→ "G&A". - GL field id =
"Category". Ramp's native GL-account field is NOT returned byGET /accounting/fields(which lists only the customcarbon-cost-centerfield); itsfield_external_idis"Category", discovered from a real coded transaction'scategory_infoand confirmed by the draft read-back. - Amount is decimal major-units. Sent
amount: 12.34; Ramp stored1234minor units (minor_unit_conversion_rate: 100). The job already sends document-currency decimals. - PDF is not a body field.
document_urlsin the create body is ignored; attachments go through a separatePOST /bills/drafts/{id}/attachments(deferred follow-up). - Submit is NOT used.
POST /bills/drafts/{id}/submit400sBILL_PAY_7145 — "bill due date, bill issued date, payment method, payee contact". Payment method + payee contact are per-vendor Ramp bill-pay config Carbon does not own, so Carbon hands off a draft and the customer completes/pays it in Ramp. - Drafts are undeletable.
DELETE /bills/drafts/{id}→ 405;DELETE /bills/{id}on a draft id → 404. So there is no archive-on-settlement for a pushed draft; once handed off, Ramp owns the bill lifecycle.
Sandbox residue: a few throwaway DRAFT provisional bills (d373921f…, e1e7ae26…,
d1c7c5c8…) created during verification could not be deleted (drafts have no delete
endpoint). They are DRAFTs, not bills, so they do not surface in GET /bills or the inbound
sync. Harmless. The last one (d1c7c5c8…, remote_id = pi_TaGAKyVaYgmTT3d97LoEhL,
invoice_number AP000003-e2e2) is the end-to-end proof: coded from a REAL posted Carbon
invoice's journal account (6090 Travel & Entertainment) and read back correctly coded.
End-to-end verification (2026-09-11, /test)
The browser reliably created a purchase-invoice header for a non-Employee supplier
(AstroMill Machining), but the line-item + posting UI flow was too fragile to drive
headlessly (combobox commit + tab churn), so the push itself was proven against a REAL
posted invoice: loadBillCostingLines for AP000003 (pi_TaGAKyVaYgmTT3d97LoEhL) returns
exactly one costing line — account acct_7Dar1tc6okPYA4EahHMezh (6090 Travel &
Entertainment, $863.57), AP control (2010) excluded — and that account is pushed to Ramp.
Pushing it to the sandbox (remote_id only) returned 201 and read back coded
Category → Travel & Entertainment (6090) at $863.57. This is the account-source rework
verified against live Ramp with real Carbon posted-journal data.
Parts (item-line invoices) — verified
A part invoice line carries a NULL accountId; posting resolves the real account, which the
rework reads from the journal:
- AP000001 (no-PO part) posts the part to 1210 Raw Materials (Asset).
- AP000389 (PO-backed part) posts to 2125 GR/IR Clearing (Liability).
codingAccountScope was REMOVED and the default is now effectively "all". Key finding: that
scope only ever controlled a Ramp-side visibility flag — every account is pushed to Ramp
regardless (all 81 here), and Ramp accepts coding a bill to a HIDDEN account. Verified
live: a draft coded to 1210 Raw Materials (which the old "expense" scope hid) returned 201 and
read back Raw Materials (1210). So parts code correctly under any scope; making all accounts
VISIBLE (the new default) just means the human reviewing the draft in Ramp sees the coded
account as a normal picker option instead of a hidden one.
Candidate-query fixes (#2, so posted part bills actually push)
The real job exposed two candidate-selection bugs, now fixed and unit-tested (a live job run to observe them needs the Inngest worker to reload the new code):
- Overdue view status added to
INVOICE_PUSH_STATUSES(a posted-unpaid invoice past its due date reportsOverdue, and was silently excluded). - The invoice push now pages on
createdAt(notupdatedAt):purchaseInvoice.updatedAtis null until an app-level edit (posting never sets it), so the updatedAt keyset made every posted invoice invisible; and the first-run cursor no longer floors at the integration's ownupdatedAt(which excluded all pre-existing open payables). The push is create-once (mapping-guarded), socreatedAtis a sufficient page key.
Validation
pnpm --filter @carbon/ee test— 1163 passed (incl. newcoding+draft-bill-push).pnpm --filter @carbon/jobs test(ramp-sync-outbound) — 694 passed.pnpm exec turbo run typecheck --filter=@carbon/ee --filter=@carbon/jobs— clean.- Biome — clean (pre-existing
console.errorwarnings only).