Cleanup Deals
Standardize deal data to make pipeline reporting accurate. Test deals, missing amounts, and stale opportunities distort forecasts and pipeline metrics.
Prerequisites
- - HubSpot API token in INLINECODE0
- Python with
hubspot-api-client installed via INLINECODE2 - Knowledge of which deal pipelines are active and which are synced from Salesforce
Important: Salesforce Sync Considerations
If deals are synced from Salesforce:
- - Do NOT delete or modify synced deals without coordinating with the Salesforce admin.
- Changes in HubSpot may sync back to Salesforce and cause data loss.
- Identify synced deals by checking for the
hs_salesforceopportunityid property.
Step-by-Step Instructions
Stage 1: Before — Audit Deal Data
Pull deal metrics via the API:
CODEBLOCK0
Record: total deals, deals per pipeline stage, deals missing amount, deals missing close date, stale deals (open with no activity in 60+ days).
Stage 2: Execute — Clean Up
- 1. Delete test deals — search for deals with names containing "test", "demo", "sample", or with amount = $0 and no associated contacts.
- Address missing amounts — export deals without
amount and work with sales to fill in values or mark as lost. - Close stale deals — deals open with no activity in 90+ days should be reviewed with the deal owner. Set to "Closed Lost" if abandoned.
- Standardize pipeline stages — ensure all pipelines have consistent stage names and probability percentages.
- Remove unused pipelines — if a pipeline has zero active deals and is not in use, archive or delete it.
Stage 3: After — Verify
- 1. Re-run the deal audit queries. Confirm:
- Test deals removed
- Missing amount count decreased
- Stale deal count decreased
- 2. Check pipeline reports for accuracy.
Stage 4: Rollback
- - Deleted deals can be restored from HubSpot's recycling bin within 90 days.
- Stage changes and property updates can be reverted manually but there is no bulk undo.
- For Salesforce-synced deals, check the Salesforce recycle bin as well.
Tips
- - Establish a deal hygiene rule: deals without activity for 60 days get an automated reminder to the owner (build a simple workflow).
- Require
amount and closedate as mandatory deal properties to prevent future gaps.
清理交易
标准化交易数据,确保管道报告准确无误。测试交易、缺失金额和过时机会会扭曲预测和管道指标。
前提条件
- - .env 文件中配置 HubSpot API 令牌
- 通过 uv 安装 hubspot-api-client 的 Python 环境
- 了解哪些交易管道处于活跃状态,哪些从 Salesforce 同步
重要提示:Salesforce 同步注意事项
如果交易是从 Salesforce 同步的:
- - 未经与 Salesforce 管理员协调,请勿删除或修改同步的交易。
- HubSpot 中的更改可能会同步回 Salesforce 并导致数据丢失。
- 通过检查 hs_salesforceopportunityid 属性来识别同步交易。
分步操作说明
第一阶段:前期准备 — 审计交易数据
通过 API 提取交易指标:
python
from hubspot import HubSpot
from hubspot.crm.deals import PublicObjectSearchRequest
apiclient = HubSpot(accesstoken=os.getenv(HUBSPOTAPITOKEN))
缺失金额的交易
no_amount = PublicObjectSearchRequest(
filter_groups=[{
filters: [{
propertyName: amount,
operator: NOT
HASPROPERTY
}]
}]
)
缺失关闭日期的交易
no_close = PublicObjectSearchRequest(
filter_groups=[{
filters: [{
propertyName: closedate,
operator: NOT
HASPROPERTY
}]
}]
)
记录:总交易数、各管道阶段的交易数、缺失金额的交易数、缺失关闭日期的交易数、过时交易数(60天以上无活动的开放交易)。
第二阶段:执行 — 清理
- 1. 删除测试交易 — 搜索名称包含test、demo、sample或金额为$0且无关联联系人的交易。
- 处理缺失金额 — 导出没有amount的交易,与销售团队协作填写数值或标记为已丢失。
- 关闭过时交易 — 90天以上无活动的开放交易应与交易负责人审核。如已放弃,则设置为已关闭-丢失。
- 标准化管道阶段 — 确保所有管道具有一致的阶段名称和概率百分比。
- 移除未使用的管道 — 如果某个管道没有活跃交易且未被使用,则归档或删除。
第三阶段:后期 — 验证
- 1. 重新运行交易审计查询。确认:
- 测试交易已删除
- 缺失金额数量减少
- 过时交易数量减少
- 2. 检查管道报告的准确性。
第四阶段:回滚
- - 已删除的交易可在90天内从HubSpot的回收站恢复。
- 阶段变更和属性更新可手动撤销,但无法批量撤销。
- 对于Salesforce同步的交易,同时检查Salesforce回收站。
提示
- - 建立交易卫生规则:60天无活动的交易自动向负责人发送提醒(构建简单工作流)。
- 将amount和closedate设置为交易必填属性,防止未来出现数据缺失。