CPQ inside HubSpot
A configure-price-quote system built entirely inside HubSpot: a formula engine computes every quantity, cost stays on the server, and the buyer locks in one option on the published quote.
Data paths and guards
- Settings page: 8 tabs where an admin sets the catalog, formulas, tokens, templates and pages.
- Deal and rep card: Where the rep enters measurements, and where the buyer’s choice lands.
- Settings object: The configuration, stored as JSON on one custom object.
- App functions: 18 functions, the formula engine among them.
- Buyer endpoint: One CMS serverless function that takes the buyer’s choice.
- Published quote: The quote module the buyer sees, a React island on the published page.
- From Settings page to Settings object: Catalog, formulas, tokens. The 166-product catalog, the formula library, measurement tokens, trade templates and branding. An admin saves a tab.
- From Settings object to App functions: Configuration. The configuration the functions price with. Each preview and each generation.
- From Deal and rep card to App functions: Measurements and options. Inspection answers and the systems chosen for the quote. The rep previews or generates the quote.
- From App functions to Published quote: Line items, frozen config. Line items for each option, tagged by option, and the configuration frozen onto the quote. The rep generates and publishes.
- From Published quote to Buyer endpoint: The buyer’s choice. The chosen option, with the quote’s nonce. The buyer records a choice or locks one in.
- From Buyer endpoint to Deal and rep card: Choice written to the deal. The choice, re-priced on the server, written to deal properties. Each accepted choice.
- From Buyer endpoint to Published quote: Republished, same URL. The quote with the other options’ lines archived. The buyer locks in one option.
- On App functions: No eval, whitelisted tokens. Formulas run in a parser that knows only whitelisted tokens and throws on anything else, with caps on input; nothing runs through eval.
- On Line items, frozen config: Sell-side lines only. The page gets the frozen configuration and whitelisted sell-side lines; cost and margin stay on the server.
- On The buyer’s choice: Per-quote nonce. The endpoint accepts a choice only with that quote’s own nonce, then re-prices it on the server.
- Built by me
- Platforms I connect to
- Guards
- Active
| Catalog, formulas, tokens The 166-product catalog, the formula library, measurement tokens, trade templates and branding |
|---|
| Configuration The configuration the functions price with |
| Measurements and options Inspection answers and the systems chosen for the quote |
| Line items, frozen config Line items for each option, tagged by option, and the configuration frozen onto the quote |
| The buyer’s choice The chosen option, with the quote’s nonce |
|---|
| Choice written to the deal The choice, re-priced on the server, written to deal properties |
| Republished, same URL The quote with the other options’ lines archived |
-
Systems
Admins configure quoting on a settings page, and reps work from a card on the deal. App functions hold the formula engine, one custom object keeps the configuration, and a CMS endpoint takes the buyer’s choice. There is no outside server or database.
-
Data paths
The admin’s catalog, formulas and tokens are saved on one custom object. A rep enters the inspection measurements; the functions compute every quantity, write the line items for each option and publish the quote with its configuration frozen on it.
- a Catalog, formulas, tokens
- b Configuration
- c Measurements and options
- d Line items, frozen config
-
Buyer’s choice
The buyer switches between options on the quote and records a choice, which the endpoint re-prices and writes to the deal. Locking in one option archives the other lines and republishes the quote at the same URL.
- e The buyer’s choice
- f Choice written to the deal
- g Republished, same URL
-
Guards
Formulas run without eval, against a token whitelist. The published page gets only sell-side lines, so cost and margin stay on the server. The endpoint accepts a choice only with the quote’s own nonce.
- No eval, whitelisted tokens on Functions
- Sell-side lines only on d
- Per-quote nonce on e
-
Result
HubSpot named it a semi-finalist in its custom-coded quote template contest, and its Revenue Hub CPQ team gave it an honorable mention. The showcase quote carries 5 options and 136 line items for a fictional contractor.
A buyer’s choice that never reached the CRM
Roofing contractors quote in bolt-on tools and paste a flat PDF into HubSpot, so the buyer’s choice never becomes CRM data. HubSpot’s custom quote modules, still in beta, only display, freeze at publish and carry their data in the public page source.
What I built
- A formula engine with a lexer, a shunting-yard parser and an RPN evaluator: no eval, a token whitelist that throws on anything unknown, and caps on runaway input.
- A rep card on the deal: an inspection questionnaire whose questions depend on earlier answers, and a live preview of three options.
- An 8-tab settings page for pricing and margin, formulas, measurement tokens, trade templates, proposal pages, kits, branding and financing.
- 18 app functions, and one CMS serverless endpoint that takes the buyer’s choice with a per-quote nonce.
- A React quote module that renders from a configuration frozen onto the quote at generation, with only sell-side lines on the page.
- Lock-in: the buyer picks one option, the other lines are archived and the quote is republished at the same URL.
What the guards protect against
| The risk | The guard |
|---|---|
| A formula runs arbitrary code, or a runaway input stalls the engine. | No eval, whitelisted tokens Formulas run in a parser that knows only whitelisted tokens and throws on anything else, with caps on input; nothing runs through eval. |
| Cost and margin appear in the public page source. | Sell-side lines only The page gets the frozen configuration and whitelisted sell-side lines; cost and margin stay on the server. |
| A forged post writes a choice to the deal. | Per-quote nonce The endpoint accepts a choice only with that quote’s own nonce, then re-prices it on the server. |
Decisions
-
Keep cost and margin off the published page
- Chose
- Cost and margin are computed on the server only; the quote page renders from a configuration frozen at generation and a whitelist of sell-side lines.
- Instead of
- Passing the pricing configuration to the quote module. Quote modules carry their props in the public page source, where any buyer could read cost and margin.
- Trade-off
- A generated quote keeps the configuration it was frozen with; a later catalog change reaches it only when the quote is generated again.
-
Publish through the Quotes API, not the quote wizard
- Chose
- The rep card creates and publishes each quote through the Quotes API, in a 5-step recipe.
- Instead of
- HubSpot’s create-quote wizard. Templates of this type never appear in the wizard’s template picker.
- Trade-off
- Quotes on this template start from the rep card, never from HubSpot’s own quote flow.
Results
- Named a semi-finalist in HubSpot’s custom-coded quote template contest, with an honorable mention from its Revenue Hub CPQ team.
- A catalog of 166 products across 5 trades, with quantities computed from 134 measurement tokens.
- On first import, 89 of 93 library formulas and 123 of 127 product formulas evaluated clean, and the first live run matched a hand calculation.
- Lock-in proven on the showcase quote: 5 options and 136 line items, re-priced and republished at the same URL.
Facts
- Builds cut from 10m6s to 1m8s by adding lockfiles
- The settings page tests any formula and shows its working
- The PDF of a quote hides the buyer’s interactive controls
- Lock-in returns the quote to draft and republishes it, the step that re-totals a quote and keeps its URL
Related builds
-
QuickBooks job costing
Date: Aug 2026
Fact: On day one of a 3-day hackathon, an invoice posted through the approval gate
Client: For contractors on HubSpot (a hackathon build)
Systems: QuickBooks Online, Stripe and Claude
Status: Active
-
Deal creation app
Date: Dec 2025
Fact: One contractor created 1,395 deals with it, January to August 2026
Client: For four roofing contractors
Systems: CompanyCam, Smarty, Shovels and NOAA weather radar
Status: In production
-
Per-trade deal budgets
Date: Feb 2026
Fact: Revenue, material and labor budgets across 11 trades
Client: For a residential roofing and exteriors contractor
Systems: SumoQuote and Zuper
Status: In production