HubSpot is known for its visual drag-and-drop workflows. But there comes a point when standard automations fall short: you need complex conditional logic, calculations, or calls to external APIs. That's where Operations Hub and its custom code actions come in.
What Is Operations Hub?
Operations Hub is HubSpot's hub designed for operations teams (RevOps). Its standout feature is Custom Code Actions: JavaScript or Python code blocks you can insert into any workflow.
This means that within a workflow you can:
- Execute JavaScript/Python code with custom logic
- Call external APIs directly from the workflow
- Transform and format data before saving it
- Create complex branching logic that isn't possible with standard conditions
Practical Example: Custom Lead Scoring
Imagine you want a more sophisticated scoring system than HubSpot's native one. You can create a workflow with custom code that evaluates multiple factors:
// Custom Code Action - Advanced Lead Scoring
exports.main = async (event, callback) => {
const { email, company, phone, country } = event.inputFields;
let score = 0;
// Corporate email is worth more
if (email && !email.includes('gmail') && !email.includes('hotmail')) {
score += 30;
}
// Has a defined company
if (company && company.length > 0) {
score += 20;
}
// Left a phone number
if (phone && phone.length > 5) {
score += 25;
}
// Target country
if (['AR', 'MX', 'CO', 'CL'].includes(country)) {
score += 25;
}
callback({
outputFields: {
lead_score: score,
lead_tier: score >= 75 ? 'Hot' : score >= 50 ? 'Warm' : 'Cold'
}
});
};
Advanced Use Cases
1. Automatic Data Enrichment
When a new lead comes in, the workflow calls an enrichment API (like Clearbit or Apollo) to get additional information: job title, company size, industry, etc. Everything is automatically saved to the contact's properties.
2. Intelligent Lead Routing
Instead of simple round-robin, you use code to assign leads based on: geographic territory, current salesperson workload, industry specialization, or estimated deal value.
3. Bidirectional ERP Sync
When a deal changes stage in HubSpot, the custom code sends the data to the ERP. When the ERP generates an invoice, a webhook updates the deal in HubSpot with the invoice number.
4. Smart Notifications
Send alerts to Slack or Discord with enriched context: not just "new lead", but data like scoring, company, recent activity, and the recommended action for the salesperson.
"With Operations Hub and custom code, we automated 80% of the operations team's manual tasks. What used to take 2 hours daily now runs on its own."
Limitations to Keep in Mind
- Execution time: maximum 20 seconds per code action
- Memory: limited, not meant for processing large files
- Libraries: only a subset of npm packages are available
- Debugging: the testing environment is limited, we recommend testing the logic separately first
When Should You Use Custom Code?
Use custom code when:
- You need complex conditional logic (more than 3 levels of if/else)
- You need to call an external API within the workflow
- You need to transform data (format dates, calculate values, parse text)
- You want to validate data before creating or updating records
Want to automate complex processes in HubSpot?
Our development team can create the custom automations your business needs.
Schedule free consultation