Timing your lead assignments can help optimize sales team performance and increase conversion rates. With HubSpot and Operations Hub Pro, you can automate this process by assigning leads based on the day they were added to your CRM. This guide walks you through creating a workflow that updates a custom property with the day of the week and uses it to segment and assign leads.
Step 1: Create a Private App
- Set Up the Private App:
- Navigate to Settings > Integrations > Private Apps in your HubSpot account.
- Create a new private app with a descriptive name like "Day of the Week."
- Under scopes, ensure you enable Write Access for Contacts.
- Save the private app and copy the private app key. You’ll use this key in your custom-coded action.
Step 2: Create a Custom Property
- Add a New Property:
- Navigate to Settings > Properties > Contact Properties.
- Create a property named Day of the Week with the following specifications:
- Field Type: Dropdown
- Options: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
This property will store the day of the week when a contact is signed.
Step 3: Write the Custom Code Action
- Set up the Workflow
- Schedule the workflow to run daily, preferably at the start of each day, to ensure accurate day-of-the-week updates
- Set Up a Custom Coded Action:
- In your workflow, add a custom-coded action.
- Paste the following code into the action editor. This code updates the custom property with the current day of the week.
const axios = require('axios');
// Get the current day of the week
const currentDate = new Date();
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const dayOfWeek = daysOfWeek[currentDate.getDay()];
// Define the HubSpot API endpoint
const HUBSPOT_API = "https://api.hubapi.com/crm/v3/objects/contacts";
// Use your private app token
const HUBSPOT_API_TOKEN = "pat-na1-bf59b1c0-3245-48d3-abf5-ccd3d37fd599";
// Function to update the contact
exports.main = async (event) => {
try {
// Extract the contact ID from the workflow context
const contactId = event.object.objectId;
// API call to update the contact property
const response = await axios.patch(
`${HUBSPOT_API}/${contactId}`,
{
properties: {
day_of_the_week: dayOfWeek // Replace "day_of_the_week" with the internal name of your custom property
}
},
{
headers: {
Authorization: `Bearer ${HUBSPOT_API_TOKEN}`,
"Content-Type": "application/json"
}
}
);
console.log("Contact updated successfully:", response.data);
} catch (error) {
console.error("Error updating contact:", error.response?.data || error.message);
throw new Error("Failed to update the contact property.");
}
};
Step 4: Build Your Workflow
-
Create a Workflow:
- Navigate to Automation > Workflows and create a new workflow for contacts.
-
- Choose the appropriate enrollment criteria for your contact assignments.
-
Branch the Workflow:
- Add branches for each day of the week using the Day of the Week property.
- Assign leads to specific sales reps based on the day of the week.
Step 5: Test
-
Test the Workflow:
- Manually enroll a test contact to verify the custom code works and updates the property correctly.
- Confirm that the correct sales reps are being assigned
Conclusion
By automating lead assignment based on the day of the week, you can streamline your sales process and better distribute workloads. With Operations Hub Pro and a little custom coding, this solution is both scalable and efficient. Implementing this process helps you optimize timing and ensure your team connects with leads when it matters most.