# HubSpot Workflow Template: Auto-Attribute Deals to Affiliate Partners

**Last Updated:** 2026-01-30

This document provides step-by-step instructions for creating a HubSpot workflow that automatically copies affiliate partner attribution from contacts to deals.

## Overview

**Purpose:** Automatically set affiliate properties on deals when:

- A deal is created or updated
- The associated contact has an `affiliate_partner_id` property set
- The deal is in "Closed Won" stage (or any stage you specify)

**Benefits:**

- Reduces manual work for sales team
- Ensures consistent attribution
- Prevents missed affiliate commissions
- Speeds up MRR calculation

## Workflow Setup Steps

### Step 1: Create New Workflow

1. Go to HubSpot → **Settings** → **Automation** → **Workflows**
2. Click **Create workflow**
3. Select **Deal-based workflow**
4. Name it: `Auto-Attribute Deals to Affiliate Partners`
5. Click **Next**

### Step 2: Set Enrollment Trigger

**Option A: Enroll when deal is created (Recommended)**

1. Click **Enrollment trigger**
2. Select **Deal created**
3. Click **Save**

**Option B: Enroll when deal is updated**

1. Click **Enrollment trigger**
2. Select **Deal property value changes**
3. Property: `Deal stage`
4. Click **Save**

### Step 3: Add Conditions (Optional but Recommended)

Add conditions to only run workflow for relevant deals:

**Condition 1: Contact has affiliate partner ID**

1. Click **Add condition**
2. Select **Contact property**
3. Property: `Affiliate Partner ID`
4. Operator: `is known`
5. Click **Save**

**Condition 2: Deal is Closed Won (Optional)**

1. Click **Add condition**
2. Select **Deal property**
3. Property: `Deal stage`
4. Operator: `equals`
5. Value: `closedwon` (or your "Closed Won" stage name)
6. Click **Save**

### Step 4: Add Actions

**Action 1: Copy Affiliate Partner ID**

1. Click **Add action**
2. Select **Set property value**
3. Object: **Deal**
4. Property: `Affiliate Partner ID`
5. Value: Select **Contact property** → `Affiliate Partner ID`
6. Click **Save**

**Action 2: Set Affiliate Subscription Status**

1. Click **Add action**
2. Select **Set property value**
3. Object: **Deal**
4. Property: `Affiliate Subscription Status`
5. Value: `Active` (or select from dropdown)
6. Click **Save**

**Action 3: Set Affiliate MRR (Optional - Manual Entry)**

**Note:** MRR typically needs to be set manually by sales since it depends on the actual subscription amount. However, you can:

**Option A: Copy from Deal Amount**

1. Click **Add action**
2. Select **Set property value**
3. Object: **Deal**
4. Property: `Affiliate MRR`
5. Value: Select **Deal property** → `Amount`
6. Click **Save**

**Option B: Leave Empty (Sales Sets Manually)**

- Skip this action
- Sales team will set MRR manually when creating deals

### Step 5: Activate Workflow

1. Review all actions
2. Click **Activate** in the top right
3. Confirm activation

## Workflow Logic Summary

```
IF Deal is created/updated
AND Contact has Affiliate Partner ID
AND Deal stage is Closed Won (optional)
THEN:
  - Set Deal.Affiliate Partner ID = Contact.Affiliate Partner ID
  - Set Deal.Affiliate Subscription Status = Active
  - Set Deal.Affiliate MRR = Deal.Amount (optional)
```

## Testing the Workflow

### Test Scenario 1: New Deal with Affiliate Contact

1. Create a test contact with `Affiliate Partner ID` = `AP-TEST-123`
2. Create a new deal and associate it with the contact
3. Set deal stage to "Closed Won"
4. **Expected:** Deal should automatically get:
   - `Affiliate Partner ID` = `AP-TEST-123`
   - `Affiliate Subscription Status` = `Active`

### Test Scenario 2: Existing Deal Updated

1. Find an existing deal with an affiliate contact
2. Update the deal (change stage, add note, etc.)
3. **Expected:** If conditions are met, affiliate properties should be set

### Test Scenario 3: Deal Without Affiliate Contact

1. Create a deal with a contact that has no `Affiliate Partner ID`
2. **Expected:** Workflow should not run (condition fails)

## Advanced Options

### Option 1: Only Run for Specific Deal Types

Add condition:

- Deal property: `Deal type` equals `New Business`

### Option 2: Copy Referral Date

Add action:

- Set Deal property: `Affiliate Referral Date` = Contact property `Affiliate Referral Date`

**Note:** Deal doesn't have `affiliate_referral_date` property by default. Only contacts have this property.

### Option 3: Send Notification

Add action:

- Send internal notification to sales team when affiliate deal is attributed

### Option 4: Update Deal Amount Based on MRR

If you want to sync MRR back to deal amount:

- Add action: Set Deal property `Amount` = Deal property `Affiliate MRR`

## Troubleshooting

### Workflow Not Running

**Check:**

1. Is workflow activated?
2. Do contacts have `Affiliate Partner ID` set?
3. Are conditions too restrictive?
4. Check workflow activity log for errors

**Fix:**

1. Review enrollment triggers
2. Test with a contact that has affiliate ID
3. Temporarily remove conditions to test

### Properties Not Setting

**Check:**

1. Are property names correct? (case-sensitive)
2. Do properties exist in HubSpot?
3. Are properties in the correct property group?

**Fix:**

1. Verify property names match exactly: `affiliate_partner_id`, `affiliate_subscription_status`, `affiliate_mrr`
2. Run verification script: `php v2/scripts/hubspot/verify-affiliate-setup.php`

### MRR Not Accurate

**Cause:** Workflow copies deal amount, but actual MRR may differ.

**Fix:**

- Remove MRR action from workflow
- Have sales team set MRR manually
- Or create a separate workflow that prompts sales to set MRR

## Best Practices

1. **Test First:** Create workflow in draft mode, test with sample deals, then activate
2. **Monitor:** Check workflow activity log weekly to ensure it's running correctly
3. **Document:** Add notes to workflow description explaining when it runs
4. **Backup:** Keep manual process as backup until workflow is proven reliable
5. **Review:** Periodically review deals to ensure attribution is correct

## Related Documentation

- [HUBSPOT_SALES_WORKFLOW.md](HUBSPOT_SALES_WORKFLOW.md) - Manual attribution process
- [HUBSPOT_SETUP.md](HUBSPOT_SETUP.md) - Technical setup guide
- [ARCHITECTURE.md](ARCHITECTURE.md) - System architecture
