Skip to content
HubSpot Solution Blueprint

Automating Many-to-Many Insurance Agent Hierarchies via Custom NPN Objects and Python Cleanup Loops

Hero featured image

A health-insurance web broker manages 16M+ enrollees. Many-to-many agent and agency relationships kept overwriting each other in the CRM. A Custom NPN Object architecture in HubSpot fixed that. Python cleanup loops in Operations Hub resolve the API race conditions. They also lock in accurate multi-tiered commission reporting.

Executive Summary

context-header-icon

Context

A healthcare.gov certified web broker needed to migrate from ActiveCampaign to HubSpot while integrating a custom ExchangeCompare API. They were managing over 85,000 legacy records and hundreds of carrier relationships, and they had to do it while preparing for the high-volume Open Enrollment Period (OEP).

what-we-built-header-icon

What We Built

We built a Custom Object architecture centered on the National Producer Number (NPN). We deployed Python-based automation to manage many-to-many associations. A daily "cleanup loop" catches orphaned records caused by API sync delays and links them.

tech-stack-header-icon

Tech Stack

  • Marketing Hub Enterprise, Operations Hub Professional, Custom ExchangeCompare API, Mixpanel, and Python.

This isn’t a fit for 1:1 agent-agency relationships. It also isn’t a fit when you lack Operations Hub Professional to run the custom code blocks that association retries need.

the-challenge-header-icon

The Challenge

Data volume wasn’t the deeper issue. Timing was. The ExchangeCompare integration pushed data in batches, so we frequently ran into race conditions. An Agent record would hit HubSpot, but the API wouldn’t create the associated Agency record for another 12 to 24 hours. In a standard setup, the association would just fail, and the agent would sit orphaned in the CRM.

Reporting added its own mess. When we tried native HubSpot roll-up properties to track total enrollments across a hierarchy, agent to parent agency to root agency, the system double-counted. It aggregated the direct agent’s enrollments and the agency’s roll-up total at the same time. When we compared those numbers to the firm’s internal Mixpanel dashboards, the HubSpot data looked like a hallucination.

our-approach-header-icon

Our Approach

We stopped relying on HubSpot’s native "Associate Objects" workflow actions for the initial sync. The data came in flattened: the agent record contained the IDs for their agencies, but the agencies themselves didn’t exist in the CRM yet. Instead of letting the sync fail, we built a secondary cleanup script in Operations Hub. That script, named "[S2] Reattempt Agent to Agency Association," was built to be patient. It queries every unassociated agent record at 3:00 AM daily. It checks whether the Agency record has finally arrived. If it has, it stitches them together. If not, it marks the record for a retry the next day.

We also solved the double-counting issue by dropping recursive roll-ups. We shifted the strategy to manual, filter-based list aggregations instead. Using the "Root ID" as the sole source of truth for the hierarchy’s top level stripped out the duplicate counts and finally got the CRM to match the internal database.

impact-header-icon

Impact

check-icon

Relational Architecture Deployed

We mapped complex many-to-many agent/agency relationships using a Custom NPN Object. That fixed a critical database limitation. 30% of agents needed affiliation with multiple different agencies. The sync no longer overwrote any data.

check-icon

Automated Multi-Tiered Downlines

We built a hierarchy system with Python scripts. It automatically maps direct agencies to their "Parent" and "Root" counterparts. That gives accurate commission and enrollment tracking across three distinct layers of the organization.

check-icon

Dynamic Engagement Labeling

We built an Ops Hub scoring engine. It tracks agent activity and assigns "Most Engaged" association labels. That let the marketing team deduplicate outreach, so marketing messages went only to the most active record tied to a specific NPN.

check-icon

14-Day Onboarding SLAs Met for Every Sign-Up

We launched an onboarding pipeline. It pushed agents from zero to their first enrollment. The build included automated round-robin assignment and workflow tracking of sales touchpoints. It kept 14-day SLAs on track for every new sign-up.

Technical Blueprint
1
The architecture uses the NPN as the central node. Custom Ops Hub workflows read foreign keys (ffm_id, agency_id) from flattened Contact records to retroactively associate them with NPN and Company objects.
2
To handle API race conditions, a Python script runs on a daily 3:00 AM loop. It identifies agents missing agency associations, searches for the corresponding agency by ID, and remakes the link once the agency record appears.
3
A calculated property aggregates opens and clicks across all agent records tied to an NPN. A workflow then finds the maximum score and stamps the "Winner" email onto the NPN record for master communication.
4

We bypassed HubSpot’s native roll-ups to avoid double-counting. We built custom reports that filter only on the "Root Agency ID." Enrollments now count once, at the top of the hierarchy.

HubSpot Custom Objects bridging agent-agency relations with Ops Hub Python logic.

A Custom Object architecture bridging complex many-to-many agent and agency relationships within HubSpot. It utilizes native Operations Hub Python logic to manage API sync delays and automated record associations. This intervention resolves standard CRM data overwrites and ensures accurate multi-tiered commission reporting for health insurance brokers.

FAQ

How do you handle an agent who leaves one agency for another?
Because we use the NPN object as a bridge, we don't delete the old relationship. We update the association label to "Former" and create a new "Active" link to the new agency, preserving the historical enrollment data.
What happens if the API hits a rate limit during the OEP?
We restricted the API to net-new triggers only. Historical and bulk data updates are handled via manual CSV imports to keep the API clear for time-sensitive enrollment syncs.

Continue reading

Hero featured image
209049082793

Engineering Regional Sales Scalability: Architectural Governance in Global CRM Environments

Hero featured image
209049052783

A Regional Fiber & Managed-Service Provider

Hero featured image
209049052785

A Large Healthcare.gov-Certified Health Insurance Web Broker

Hero featured image
209049052787

A Specialized Men's-Health Telehealth Provider

Hero featured image
209049052787

A Specialized Men's-Health Telehealth Provider

Hero featured image
209049052786

A Global Environmental IoT & Infrastructure Software Provider

Hero featured image
209053190299

A Global Residential Real Estate Software Provider

Hero featured image
209049052785

A $1B+ Global Financial Data & Analytics Provider

Hero featured image
209053177394

A global industrial abrasive mining and distribution firm

Hero featured image
209049082792

A global industrial abrasive mining and distribution firm

Hero featured image
209049052787

A Global Medical Technology Manufacturer

Hero featured image
209049052787

A Global Medical Technology Manufacturer

Hero featured image
209049052787

A Multi-Site Dental Health Group

Hero featured image
209049052787

A Multi-Site Dental Health Group

Hero featured image
209049082794

A Large Metropolitan Catholic Education Diocese

Hero featured image
209049052787

A Specialized Investigational Cell Therapy Provider

Hero featured image
209049052787

A Specialized Investigational Cell Therapy Provider

Hero featured image
209049082794

A Global Wellness Training & E-commerce Provider

Hero featured image
209049052786

A Multi-Billion-Dollar Enterprise Security-Awareness Training Provider

Hero featured image
209049052785

A Tier 1 Automotive F&I Provider

Hero featured image
209049052785

A Mexican Retail Bank

Hero featured image
209049052786

A Global Leader in Live Streaming and Creator Tools

Hero featured image
209049052786

A Global Leader in Live Streaming and Creator Tools

Hero featured image
209049052786

A $1B+ Global Cloud & Edge Delivery Provider

Hero featured image
209049052785

$50M+ Enterprise FinTech SaaS provider

Hero featured image
209049082792

The $100M+ Autonomous Heavy Equipment Retrofit Provider

Hero featured image
209053177394

An Enterprise Industrial Infrastructure IoT Division

Hero featured image
209053177394

An Enterprise Industrial Infrastructure IoT Division

Hero featured image
209049052786

A Global Shipping Software and 3PL Portfolio

Hero featured image
209049052786

A Global Shipping Software and 3PL Portfolio

footerCTA footerCTA-mobile
Spice up your inbox
Sign up for our newsletter
Don't worry - we only average, like, two emojis per subject line.