Building an AI Marketing Agent with HubSpot + ChatGPT
Step-by-step guide to building an AI-powered marketing agent that combines HubSpot CRM data with ChatGPT intelligence for automated campaigns, lead scoring, and content personalization.
Last updated: July 19, 2026
Building an AI Marketing Agent with HubSpot + ChatGPT
Learn how to combine HubSpot’s CRM data with ChatGPT’s intelligence to build a marketing agent that automates campaigns, scores leads, and personalizes content at scale.
What You’ll Build
An AI-powered marketing agent that:
- Reads HubSpot CRM data — contacts, deals, email performance
- Analyzes with ChatGPT — lead scoring, content recommendations, campaign optimization
- Takes action — updates HubSpot records, drafts content, triggers workflows via Zapier
Prerequisites
- A HubSpot account with API access (any tier works)
- An OpenAI API key (ChatGPT/ GPT-4)
- A Zapier account (for no-code integration) or access to HubSpot’s API directly
- (Optional) Hermes Agent for skill-based orchestration
Step 1: Connect HubSpot to ChatGPT via API
Option A: Direct API Connection (Developer-Friendly)
# Test HubSpot API connection
curl -s "https://api.hubapi.com/crm/v3/objects/contacts" \
-H "Authorization: Bearer YOUR_HUBSPOT_ACCESS_TOKEN" \
-H "Content-Type: application/json" | jq '.results | length'
Option B: Zapier Bridge (No-Code)
- Create a new Zap: HubSpot + ChatGPT
- Trigger: Contact Created or Deal Stage Changed in HubSpot
- Action: ChatGPT — Send Prompt with HubSpot data
- Response: Update HubSpot via Update Contact action
Step 2: Define Your Marketing Agent Personality
The prompt template for your AI marketing agent:
You are a Senior Marketing Operations Agent at {COMPANY_NAME}.
Your role is to:
1. SCORE leads based on: engagement level, company size, industry fit, email history
2. RECOMMEND next actions: send brochure, book demo, add to nurture sequence
3. DRAFT personalized follow-up emails using HubSpot contact data
4. ANALYZE email campaign performance and suggest improvements
5. FLAG high-value accounts for immediate sales attention
Available data: {CONTACT_FIELDS: name, company, title, email_opens, website_visits, deal_stage}
Channel: Email (HubSpot), CRM updates (HubSpot), Internal alerts (Slack)
Step 3: Build the Lead Scoring Workflow
Hermes Agent Skill Approach
Save as a Hermes Agent skill for reusable execution:
# Hermes Agent workflow: Score new HubSpot contacts
# 1. Fetch new contacts from HubSpot (API limit: 100)
# 2. Send each contact to ChatGPT for scoring
# 3. Update HubSpot with score + recommendation
# 4. Alert team for high-value leads via Slack
# Fetch contacts created in last 24h
CONTACTS=$(curl -s \
"https://api.hubapi.com/crm/v3/objects/contacts/search" \
-H "Authorization: Bearer $HUBSPOT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filterGroups": [{
"filters": [{
"propertyName": "createdate",
"operator": "GTE",
"value": "'$(date -d "24 hours ago" +%Y-%m-%d)'"
}]
}],
"properties": ["email", "firstname", "lastname", "company", "hs_lead_status"]
}')
Serverless Function Approach (Production)
Deploy as a Cloudflare Worker or Supabase Edge Function:
// HubSpot + ChatGPT Marketing Agent — Edge Function
const HUBSPOT_TOKEN = env.HUBSPOT_TOKEN;
const OPENAI_KEY = env.OPENAI_API_KEY;
async function scoreLead(contact) {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENAI_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "gpt-4",
messages: [{
role: "system",
content: "You are a lead scoring agent. Score leads 1-10 based on company size, title, and industry."
}, {
role: "user",
content: JSON.stringify(contact)
}]
})
});
const data = await response.json();
return data.choices[0].message.content;
}
// Run daily on new contacts
export async function scheduled(event) {
const contacts = await fetchHubSpotContacts();
for (const contact of contacts) {
const score = await scoreLead(contact);
await updateHubSpotContact(contact.id, { hs_lead_score: score });
}
}
Step 4: Automate Content Personalization
Use ChatGPT to draft personalized email sequences for HubSpot campaigns:
Cold Outreach Personalization
# For each lead in a campaign, generate personalized intro
curl -X POST "https://api.openai.com/v1/chat/completions" \
-H "Authorization: Bearer $OPENAI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "Write a marketing email intro.
Tone: Professional but warm.
Personalize using: company name, industry, contact title.
Keep it under 100 words."},
{"role": "user", "content": "Contact: VP of Engineering at Acme Corp (SaaS, 200 employees)
Product: AI-powered code review tool"}
]
}' | jq '.choices[0].message.content'
Campaign Analysis Agent
Schedule weekly campaign performance analysis:
# Hermes Agent cron job: Weekly campaign analysis
# 1. Pull HubSpot email campaign stats
# 2. Analyze with ChatGPT
# 3. Generate recommendations
# 4. Post report to Slack
curl -s "https://api.hubapi.com/marketing/v3/emails" \
-H "Authorization: Bearer $HUBSPOT_TOKEN" | \
jq '.results[] | {name, stats: {opens, clicks, replies}}' > /tmp/campaigns.json
# Send to ChatGPT for analysis
curl -s -X POST "https://api.openai.com/v1/chat/completions" \
-H "Authorization: Bearer $OPENAI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "Analyze these email campaigns.
For each: What worked? What can improve?
Suggest A/B test ideas for underperformers."},
{"role": "user", "content": "CAMPAIGN_DATA_HERE"}
]
}' | jq '.choices[0].message.content'
Step 5: Deploy as a Recurring Automation
Option 1: Hermes Agent Cron Job
# Schedule daily lead scoring at 8 AM
hermes cron create \
--schedule "0 8 * * *" \
--prompt "Run the HubSpot lead scoring agent: fetch new contacts, score with ChatGPT, update HubSpot, alert Slack for 8+ scores."
Option 2: Cloudflare Workers Cron Trigger
// wrangler.toml
// [triggers]
// crons = ["0 9 * * *", "0 14 * * *"]
Option 3: Supabase Edge Functions
Deploy via MCP: the Supabase toolset can deploy edge functions that connect HubSpot Webhooks to ChatGPT.
What to Monitor
| Metric | Target | Tool |
|---|---|---|
| Leads scored/day | All new contacts | HubSpot dashboard |
| Score accuracy | >80% agreement with manual scoring | Monthly audit |
| Email campaign CTR | +15% vs non-personalized | HubSpot email stats |
| Automation errors | <1% failure rate | Worker logs |
| API costs | <$50/month for ~5000 contacts | OpenAI usage dashboard |
Related Resources
Reviews
Guides
- How to Use ChatGPT with Your SaaS Stack
- AI Content Workflow: Canva + HeyGen
- Automate AI Pipeline with Zapier
OKF Bundles
FAQ
Q: Do I need a paid HubSpot plan to use the API? A: Yes — HubSpot API access for CRM objects requires at least the Starter plan ($50/month). Marketing Hub also requires a paid plan for email campaign APIs.
Q: Can this agent handle 10,000+ contacts? A: Yes — but you’ll hit API rate limits. Use batch processing (100 contacts per API call) and add rate limiting. The ChatGPT API handles rate limits gracefully with retry logic.
Q: What if ChatGPT’s lead scoring disagrees with my sales team? A: That’s actually valuable feedback. Log disagreements and periodically review them to tune your prompt. Over time, ChatGPT will learn your team’s preferences.
Q: Can this work without Zapier? A: Yes — use direct API calls (as shown in Step 3’s Hermes skill approach). The direct approach gives you more control but requires a small amount of code.
Q: How often should this agent run? A: Daily for lead scoring (covers new contacts), weekly for campaign analysis, and on-demand for content personalization. Running lead scoring more than once per day is usually overkill for most teams.