Case study
HubSpot silently ignored my lead updates, and only the real sandbox showed it
FunnelTrace scores each lead hot, warm or cold and, when a person approves the follow-up, writes the contact to HubSpot with a lifecycle stage that matches the score. Hot becomes salesqualifiedlead, warm becomes marketingqualifiedlead, cold becomes lead.
My automated tests passed. Then I ran the project's final check against a real HubSpot sandbox account, and it found two things that no test with a fake HubSpot could have found.
Problem 1: moving a lead backwards did nothing
A lead who writes again is re-scored. For example, a lead starts hot, then sends a message that makes them cold. My code sent HubSpot an update setting the stage back to lead. HubSpot ignored it and left the stage where it was. It doesn't apply a direct move to an earlier lifecycle stage.
The fix was to be explicit about the order and handle each case:
STAGE_ORDER = ["lead", "marketingqualifiedlead", "salesqualifiedlead"]
current_stage = current["properties"].get("lifecyclestage")
if current_stage and current_stage not in STAGE_ORDER:
# Opportunity, customer, ...: further along than anything we assign. Leave it.
del properties["lifecyclestage"]
elif current_stage and STAGE_ORDER.index(current_stage) > STAGE_ORDER.index(new_stage):
# Clearing first is the only way HubSpot accepts a move back.
self._request("PATCH", path, {"properties": {"lifecyclestage": ""}})
self._request("PATCH", path, {"properties": properties})
The code now reads the contact's current stage first. If the contact is already an opportunity or a customer, it leaves the stage alone, because a lead-scoring tool shouldn't pull a paying customer back to "lead". If the move is backwards, it clears the stage first, which is the only way HubSpot accepts it.
Problem 2: the phone lookup missed new contacts
To avoid creating a duplicate contact, the code searches HubSpot for the lead's email and phone before creating one. The phone search used an exact match, and a contact created moments earlier wasn't found yet because HubSpot's search index lags behind its writes. The code could then create a second contact for the same person.
I changed the phone search to match on a token instead of an exact value, which finds the contact sooner and tolerates formatting differences.
What the two had in common
Both bugs are the API behaving differently from what my mocks assumed. A mock returns whatever you told it to, so my tests proved only that my code did what I expected. The real service showed what it actually does. I added tests for both cases afterwards, so they stay fixed.
What this doesn't cover
- The indexing lag can still duplicate a phone-only contact that was created seconds earlier, or created outside the app. The token search reduces it and doesn't remove it.
- A mistyped email blocks the whole HubSpot write, and there's no retry for a failed sync yet.
- This is a free-tier sandbox with fake leads, not a client's CRM.
What I'd tell a client
If your workflow writes to a CRM, plan one run against the real service, with real account settings, before you call it done. The failures that cost you are the silent ones, where the API says success and nothing changes. That is a short test to run, and it's the one that finds them.
The code from this post is public: https://github.com/hassan91199/funneltrace/blob/main/backend/funneltrace/crm.py.
If a CRM integration has been quietly doing less than you think, book a call with me on Upwork.