New contact hygiene workflow

From TomGranot/hubspot-admin-skills · View interactive version

New contact hygiene workflow is an AI agent skill from the GitHub repository TomGranot/hubspot-admin-skills. Build a HubSpot workflow that auto-enriches and stages new contacts upon creation. Sets lifecycle stage via the v4 Automation API, copies company name and industry from the associated company (UI step), and branches on completeness.

How to use this skill

Skill file

New Contact Hygiene Workflow

Build a workflow that automatically enriches every new contact at creation time. This ensures contacts enter the database with a lifecycle stage, company name, and industry before any human touches them.

What Is and Isn't Scriptable

API status: HubSpot documents the Workflows API as beta and subject to change. Its current reference is the date-based beta path /automation/v4/2027-03-beta/flows; this skill's scripts still call the unversioned /automation/v4/flows path, which v4's end of support on March 30, 2027 also covers. Creating workflows disabled and reviewing them in the UI is what makes a beta API acceptable here. If a script's create call starts failing, the manual UI build below is the fallback.

The v4 Automation API creates workflows programmatically, including "is unknown" enrollment conditions via LIST_BASED filter criteria. Two pieces of this particular design still belong in the UI:

  1. Copy from associated object actions (copy company name/industry from the associated company) have no documented v4 action fields. Add them in the UI during review — or build the action once in the UI, GET /automation/v4/flows/{flowId}, and extend the script with the exact field shapes your portal returns.
  2. The notification branch (alert admin when a contact still has no company after the delay) depends on portal-specific recipients.

So the split is: the script creates the default-lifecycle-stage workflow via API; the enrichment copy actions and the notification branch are added in the UI. If you already run /enrich-company-name and /enrich-industry, their dedicated workflows cover the copy actions and this skill's API-created workflow completes the intake picture.

Prerequisites

Scripts

Script paths are relative to this skill's directory. Run them from your project directory so .env, data/, and reports/ resolve there: prefix each path with wherever this skill is installed (skills/new-contact-hygiene-workflow/ in a clone of the repo).

| Stage | Script | Run with |

|-------|--------|----------|

| Before | CODE0 | uv run scripts/before.py |

| Execute | CODE0 | uv run scripts/execute.py |

| After | CODE0 | uv run scripts/after.py |

execute.py creates one workflow — "HYGIENE: Default Lifecycle Stage for New Contacts" (enrollment: create date known AND lifecycle stage unknown; action: set stage to Lead; re-enrollment on) — disabled, for review before enabling. Extend it in the UI with the copy actions and notification branch per the design below.

Building the Workflow: Two Options

Option A (primary): run the scripts, then extend the created workflow in the UI with the copy-from-associated-company actions, the delay, and the no-company notification branch (Stage 3, steps 3-6).

Option B: build the whole workflow manually in the UI (all of Stage 3).

Alternatives: HubSpot Breeze AI provides minimal value for this workflow — it creates event-based (OR) triggers, and cannot create "is unknown" conditions, copy-from-association actions, or re-enrollment rules. The Claude Chrome extension can drive the workflow builder UI directly and handles those cases. Both are secondary options.

Workflow Design

TRIGGER: Contact create date is known
         (fires for every new contact)
           │
           ▼
    ┌─────────────────────────┐
    │ Set lifecycle stage      │
    │ = "Lead" (if empty)      │
    └────────────┬────────────┘
                 │
                 ▼
    ┌─────────────────────────┐
    │ Copy company name from   │
    │ associated company       │
    └────────────┬────────────┘
                 │
                 ▼
    ┌─────────────────────────┐
    │ Copy industry from       │
    │ associated company       │
    └────────────┬────────────┘
                 │
                 ▼
    ┌─────────────────────────┐
    │ Delay: short wait         │
    │ (3-10 min, rec: 5)      │
    └────────────┬────────────┘
                 │
                 ▼
    ┌─────────────────────────┐
    │ IF/THEN BRANCH:          │
    │ Company name is unknown? │
    ├──────────┬──────────────┘
    │ YES      │ NO
    │          │
    ▼          ▼
  Retry      Continue
  copy       (enriched)
  + notify
  admin

Step-by-Step Build Instructions

Stage 1: Plan

  1. Confirm the default stage for new contacts (Lead, unless your funnel differs).
  2. Decide who receives the "no company association" notification.

Stage 2: Before

  1. Confirm company enrichment processes have run for existing data.
  2. Run uv run scripts/before.py to inventory workflows and check name collisions.

Stage 3: Execute

Option A: run uv run scripts/execute.py, then open the created workflow in the UI and continue from step 3 below (copy actions, delay, branch). Option B: open HubSpot > Automation > Workflows > Create workflow, select "Contact-based", start from scratch, and follow all steps.

  1. Set enrollment trigger:
  1. Add action: Set property value
  1. Add action: Copy property
  1. Add action: Copy property
  1. Add delay: a short delay (3-10 minutes, recommended: 5)
  1. Add if/then branch:
  1. Review settings:
  1. Turn on the workflow.

Stage 4: After

  1. Run uv run scripts/after.py (API path) to confirm the workflow exists and report enabled state.
  2. Create a test contact manually. Confirm:
  1. Create a test contact with no company association. Confirm:
  1. Check workflow history for any errors in the first 24 hours.

Rollback

  1. Turn off the workflow in HubSpot > Automation > Workflows.
  2. Contacts already enriched retain their values — no destructive changes to undo.
  3. If lifecycle stages were set incorrectly, use the Search API to find contacts created after the workflow activation date and reset as needed.

Edge Cases

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.