DEV Community

Cover image for Fixing Broken ERP Syncs and Schema Drift in ServiceTitan v2 with V8 Edge Middleware

Fixing Broken ERP Syncs and Schema Drift in ServiceTitan v2 with V8 Edge Middleware

Last week I wrote about handling HTTP 429 burst lockouts and OAuth token stampedes when piping high-volume lead traffic into ServiceTitan v2.

Rate limiting solves the transport bottleneck, but it does nothing for the actual payload errors that quietly kill inbound workflows. Fragile iPaaS workflows and post-merger roll-up stacks silently drop 6% to 9% of paid Google LSA, Meta, aggregator, and ERP sync payloads under burst concurrency, database locks, and unannounced schema drift.

If you manage infrastructure for multi-branch trade fleets, Zapier and Make usually choke on three specific edge cases:

  1. Bracketed Accounting Negatives: Upstream warehouse feeds pass discounts as ($450.00). Naive parsers drop the field entirely or ingest it as a string, ruining Sage Intacct and NetSuite reconciliation.
  2. Single-Item XML Array Collapse: A purchase order with exactly one line item gets parsed as a flat object instead of an array. The strict downstream ERP schema rejects the entire payload.
  3. Multi-Trade Job Note Bleed: A commercial facility manager types "water heater leaking and breaker box sparking". Basic routers dump this into a single default trade bucket instead of flagging a critical cross-dispatch.

Kalloway & Thayer Systems LLC provisions zero-dependency Node.js edge runtimes that intercept raw webhooks and pace normalized payloads into ServiceTitan v2 and downstream ERP ledgers with zero HTTP 429 throttling.

Here is how we handle schema compilation and cross-trade routing in sub-millisecond time.

1. Compiling Bracketed Negatives and XML Arrays

Before you can inject a warehouse purchase order into Sage Intacct, you have to coerce the unstructured data into exact integer-cent ledger primitives.

In our V8 runtime, we intercept the webhook and run a fast parser to identify bracketed negatives and strip out currency symbols. At the same time, we check if the incoming line items are flat objects and force them into strict arrays:

function parseCurrencyCents(val) {
  if (val === null || val === undefined || val === "") return null;
  if (typeof val === "number" && Number.isFinite(val)) return Math.round(val * 100);

  const raw = String(val).trim();
  if (!raw || /^(null|undefined|n\/a|na|none|-)$/i.test(raw)) return null;

  const isNeg = /^\(.*\)$/.test(raw) || raw.startsWith("-");
  const numStr = raw.replace(/[^0-9.]/g, "");
  if (!numStr) return null;

  const cents = Math.round(parseFloat(numStr) * 100);
  return isNeg ? -Math.abs(cents) : cents;
}

const rawItems = po.line_items || po.items || po.lines;
const itemList = Array.isArray(rawItems) ? rawItems : (rawItems && typeof rawItems === "object" ? [rawItems] : []);
Enter fullscreen mode Exit fullscreen mode

This ensures a discount of ($450.00) becomes strictly -45000 before it ever touches the ERP ledger, preventing floating-point reconciliation errors downstream.

2. Cross-Trade Classification and Zero-Disk Routing

When a residential or commercial lead arrives, we run deterministic classification against the raw job text to route it correctly in ServiceTitan.

function detectTradeCategory(serviceText) {
  const text = String(serviceText).toLowerCase();

  const hasPlumbing = /plumb|pipe|water\s*heater|tankless|drain|leak|backflow/i.test(text);
  const hasElectrical = /electric|wire|panel|breaker|outlet|spark/i.test(text);
  const hasHvac = /hvac|a\/c|furnace|heat\s*pump|boiler|compressor|froze\s*up/i.test(text);

  if (hasPlumbing && hasElectrical && hasHvac) return "Commercial MEP / Multi-Trade Cross-Dispatch";
  if (hasPlumbing && hasElectrical) return "Plumbing & Electrical Cross-Dispatch";
  if (hasHvac && hasElectrical) return "HVAC & Electrical Cross-Dispatch";
  if (hasPlumbing && hasHvac) return "Mechanical / Plumbing & HVAC";
  if (hasPlumbing) return "Plumbing";
  if (hasElectrical) return "Electrical";
  if (hasHvac) return "HVAC";

  return "General_Home_Services";
}
Enter fullscreen mode Exit fullscreen mode

Once classified, the payload routes directly to the API. Customer PII is normalized in sub-millisecond volatile RAM with zero database persistence on our nodes.

3. Proving ROI With Zero Customer PII Stored

The biggest pushback from enterprise IT teams when adding an edge proxy is observability.

You do not need to store customer names or phone numbers to prove value. We track strict integer counters in memory. Payloads failing upstream schema validation route immediately to your client-owned encrypted Dead-Letter Queue (S3/Webhook) with PII-redacted telemetry alerts.

At any point, operators can pull a plain-text executive receipt to audit the pipeline:

====================================================================
KALLOWAY & THAYER SYSTEMS LLC - EDGE INGRESS TELEMETRY RECEIPT
====================================================================
Tenant Route:                    summit_mechanical_group
Zero-Data-at-Rest Posture:       VERIFIED (0 Bytes Customer PII Stored)
--------------------------------------------------------------------
Total Payloads Processed:        1,000 (Avg compute: 0.05ms)
Clean Dispatches Routed:         961
Malformed Payloads Rescued:      184 (~$22,080 ad spend preserved)
  ├─ Bracketed POs Fixed:        42
  ├─ XML Arrays Coerced:         89
  └─ Cross-Trades Flagged:       53
Duplicate Dispatches Blocked:    38 (Atomic DJB2/FNV-1a RAM shield)
HTTP 429 Burst Spikes Paced:     14 (Downstream CRM lockouts prevented)
Quarantined to Encrypted DLQ:    1 (0 Silent Drops)
====================================================================
Enter fullscreen mode Exit fullscreen mode

Try the Primitives or Run a Live Payload Test

If you are building custom webhook integrations in TypeScript or Node.js, you can pull our open-source client and normalizer primitives directly from npm:

npm i @kallowaythayer/servicetitan-v2
Enter fullscreen mode Exit fullscreen mode

If you want to see how your current webhook payloads hold up against cross-trade classification and strict ERP schema validation, drop a raw JSON string into the live sandbox on our site or check out the repo.

Top comments (0)