Setting Up Google Calendar to HubSpot Invoice Automation
This guide will show you how to set up an automated workflow that converts your Google Calendar billable hours into HubSpot invoices, complete with line items for each service type.
Features Included in This Workflow
Feature | Google Calendar to HubSpot Invoice |
---|---|
Automated invoice generation Creates HubSpot invoices from calendar events without manual data entry | |
Color-coded service tracking Maps Google Calendar event colors to specific HubSpot products | |
Automatic hour calculation Calculates billable hours from calendar event durations | |
Service type aggregation Groups hours by service type for accurate line items | |
Contact & company associations Automatically links invoices to HubSpot contacts and companies | |
Recurring event support Handles recurring calendar events properly | |
Scheduled automation Run monthly to generate invoices for the previous month | |
Fully customizable Adjust products, clients, date ranges, and more |
Prerequisites
- An n8n instance (cloud or self-hosted)
- A Google Calendar with color-coded billable events
- A HubSpot account with invoicing and products configured
- HubSpot private app with appropriate scopes
- Basic understanding of n8n workflows
How It Works
This workflow follows these steps:
- Retrieve calendar events from the previous month
- Filter for billable events (those with a colorId)
- Calculate duration of each event in hours
- Summarize hours by service type (color)
- Create HubSpot invoice with contact/company associations
- Add line items for each service type with calculated hours
Step 1: Download and Import Workflow
1.1 Download Workflow File
- Click the workflow card below to visit the workflow details page
- Click the Download button to download the workflow JSON file
- Save the file to your local computer
Google Calendar to HubSpot Invoice Automation
Automatically create HubSpot invoices from Google Calendar events. Track billable hours by service type and generate accurate invoices with line items.
1.2 Import Workflow to n8n
- Open your n8n instance
- Create a new workflow
- Click the ... menu (three dots) in the top right
- Select Import from File...
- Choose the downloaded workflow JSON file
- The workflow will appear with sticky notes containing setup instructions
Step 2: Set Up Google Calendar
2.1 Create Color-Coded Events
This workflow relies on Google Calendar event colors to identify service types. You need to:
- Open Google Calendar
- Decide which colors represent which services (e.g., red = consulting, blue = development)
- Apply colors to your billable events:
- Create or edit an event
- Click the color picker (bucket icon)
- Select a color
- Note down the mapping (you'll need this for HubSpot configuration)
2.2 Find Color IDs
Google Calendar assigns numeric IDs to colors:
- The easiest way is to run the workflow once with test data
- Look at the
colorId
field in the calendar event data - Common color IDs:
1
= Lavender2
= Sage3
= Grape4
= Flamingo5
= Banana6
= Tangerine7
= Peacock8
= Graphite9
= Blueberry10
= Basil11
= Tomato
Step 3: Set Up HubSpot
3.1 Create HubSpot Private App
- Go to your HubSpot account
- Navigate to Settings → Integrations → Private Apps
- Click Create a private app
- Give it a name (e.g., "n8n Calendar Integration")
- Under Scopes, select:
crm.objects.contacts.read
crm.objects.companies.read
crm.objects.invoices.write
crm.objects.line_items.write
- Click Create app
- Copy the access token - you'll need this for n8n credentials
Reference: HubSpot Private Apps Guide
3.2 Create Products in HubSpot
Your workflow needs HubSpot products that match your calendar service types:
- Go to Sales → Products in HubSpot
- Create a product for each service type:
- Click Create product
- Enter product name (e.g., "Consulting Hours")
- Set price per unit (hourly rate)
- Save
- Note the Product ID for each product:
- Open the product
- Look at the URL:
https://app.hubspot.com/contacts/HUBID/record/0-7/PRODUCTID
- Copy the
PRODUCTID
number
3.3 Find Contact and Company IDs
- Open a contact in HubSpot
- Look at the URL:
https://app.hubspot.com/contacts/HUBID/record/0-1/CONTACTID
- Note the
CONTACTID
- Open the associated company
- Look at the URL:
https://app.hubspot.com/contacts/HUBID/record/0-2/COMPANYID
- Note the
COMPANYID
3.4 Find Your Hub ID
- Go to HubSpot Settings → Account Setup → Account Defaults
- Your Hub ID is shown at the top
- Or, look at any HubSpot URL - it's the first number after
/contacts/
Step 4: Configure n8n Credentials
4.1 Add Google Calendar OAuth2 Credential
- In your n8n workflow, click on the Get many events node
- Under Credential to connect with, click the dropdown
- Select Create New Credential
- Choose Google Calendar OAuth2 API
- Fill in the credential details:
- Name: "Google Calendar"
- Follow the OAuth setup wizard to connect your Google account
- Click Save
- Authorize n8n to access your Google Calendar
4.2 Add HubSpot Bearer Auth Credential
- Click on the Create Invoice node
- Under Credential to connect with, click the dropdown
- Select Create New Credential
- Choose HTTP Bearer Auth
- Fill in the credential details:
- Name: "HubSpot Private App"
- Token: Paste your HubSpot private app access token
- Click Save
4.3 Attach Credentials to All Nodes
The HubSpot credential needs to be attached to:
- Create Invoice
- Add Line Items
To attach:
- Click on each node
- Under Credential to connect with, select your "HubSpot Private App" credential
- Save the node
Step 5: Configure the Workflow
5.1 Edit the Config Node
This is the most important step - the Config node centralizes all your settings.
- Double-click the Config node to open the code editor
- Update the following values:
Hub ID:
const hubId = "YOUR_HUB_ID_HERE";
Product Data: Map your Google Calendar colors to HubSpot products:
const productData = {
"Consulting": {
colorId: "11", // Google Calendar color (red/tomato)
id: "YOUR_PRODUCT_ID", // HubSpot product ID
name: "Consulting Hours" // HubSpot product name
},
"Development": {
colorId: "3", // Google Calendar color (grape/purple)
id: "YOUR_PRODUCT_ID",
name: "Development Hours"
},
"Design": {
colorId: "2", // Google Calendar color (sage/green)
id: "YOUR_PRODUCT_ID",
name: "Design Hours"
}
};
Contact Data: Update with your client information:
const contactData = {
"Acme Corp": {
contactId: "YOUR_CONTACT_ID",
contactName: "John Smith",
companyId: "YOUR_COMPANY_ID"
}
};
- Click Save
5.2 Update Calendar ID
- Double-click the Get many events node
- Under Calendar, select your Google Calendar
- If you don't see your calendar:
- Click the refresh icon
- Or, find your calendar ID in Google Calendar settings
- Save the node
5.3 Verify Association Type IDs
The workflow uses HubSpot's standard association type IDs:
- Invoice to Contact:
177
- Invoice to Company:
179
- Line Item to Invoice:
410
These should work for most accounts. If you get errors, verify these values in HubSpot's documentation.
Step 6: Test the Workflow
6.1 Add Test Calendar Events
Before running the workflow:
- Go to Google Calendar
- Add a few test events for last month:
- Event 1: 2 hours, color = consulting color
- Event 2: 3 hours, color = development color
- Event 3: 1.5 hours, color = design color
- Make sure events have the colors configured in your Config node
6.2 Manual Test Run
- Click Execute Workflow (play button) at the bottom
- Watch the nodes execute:
- Config: Sets up all configuration
- Get many events: Retrieves calendar events
- Filter: Removes events without colorId
- Edit Fields: Calculates duration in hours
- Summarize: Groups hours by color
- Create Invoice: Creates HubSpot invoice
- Prepare Line Items: Maps colors to products
- Add Line Items: Adds line items to invoice
- Check for errors in any node
6.3 Verify Invoice in HubSpot
- Go to HubSpot → Sales → Invoices
- Find the newly created invoice
- Verify:
- Invoice is associated with correct contact and company
- Line items match your calendar hours
- Each service type has correct quantity
- Currency is set correctly (USD)
Step 7: Automate with Schedule Trigger
7.1 Replace Manual Trigger
- Delete the Manual trigger node (or disconnect it)
- Add a Schedule Trigger node:
- Click + to add a new node
- Search for "Schedule Trigger"
- Add it to the workflow
- Connect it to the Config node
7.2 Configure Monthly Schedule
- Double-click the Schedule Trigger node
- Set the schedule:
- Trigger Interval:
Months
- Trigger on Day: Select day of month (e.g.,
1st
) - Trigger at Hour: Select hour (e.g.,
9 AM
)
- Trigger Interval:
- Click Save
This will run the workflow on the 1st of each month at 9 AM, creating an invoice for the previous month.
7.3 Activate the Workflow
- Click the Active toggle at the top of the workflow
- The workflow will now run automatically each month
Customization Options
Add Multiple Clients
To handle multiple clients, you have two options:
Option 1: Duplicate Workflow (Recommended)
- Duplicate the entire workflow
- Rename it (e.g., "Invoice - Client B")
- Update the Config node with client B's data
- Each client gets their own automated workflow
Option 2: Add Client Selection Logic
- Add a node after Config that determines which client
- Use an IF node to route to different invoice creation branches
- More complex but keeps everything in one workflow
Change Date Range
By default, the workflow processes the previous month. To customize:
- Edit the Config node
- Find the
dateRanges
section:
dateRanges: {
previousMonthStart: DateTime.now().minus({ months: 1 }).startOf('month').toISO(),
previousMonthEnd: DateTime.now().startOf('month').toISO()
}
For last 30 days:
dateRanges: {
previousMonthStart: DateTime.now().minus({ days: 30 }).toISO(),
previousMonthEnd: DateTime.now().toISO()
}
Add Custom Invoice Properties
To set additional invoice fields:
- Edit the Create Invoice node
- Add properties to the JSON body:
{
"properties": {
"hs_currency": "USD",
"hs_due_date": "2025-11-30",
"hs_invoice_name": "Monthly Services - October 2025"
}
}
Filter Non-Billable Events
Currently, the workflow filters for events WITH a colorId. To add more filters:
- Edit the Filter node
- Add additional conditions:
- Event summary contains certain text
- Event is in a specific calendar
- Event duration is above a minimum
Send Notification After Creation
To get notified when invoices are created:
- Add a Send Email node or Slack node at the end
- Map invoice data to the message:
- Invoice ID
- Total hours
- Line item breakdown
- Send to yourself or your accounting team
Troubleshooting
Common Issues
1. "Unauthorized" or "Invalid Credentials" Error
- Solution: Re-authorize your Google Calendar OAuth2 credential
- Go to Credentials → Click your credential → Reconnect Account
2. "Calendar not found" Error
- Solution: Verify calendar ID in the Get many events node
- Make sure you selected the correct calendar from the dropdown
3. "Product not found" in HubSpot
- Solution: Double-check product IDs in the Config node
- Go to HubSpot → Products → Open product → Copy ID from URL
4. No Events Retrieved
- Solution: Check date range
- Make sure events exist in the specified date range
- Verify events have a colorId set
5. Invoice Created but No Line Items
- Solution: Check Summarize node output
- Verify colorMappings in Config match your event colors
- Ensure products exist in HubSpot with correct IDs
6. Association Errors
- Solution: Verify association type IDs
- Check that contact and company IDs are correct
- Make sure contact is associated with the company in HubSpot
7. Events Without Duration
- Solution: Make sure calendar events have both start and end times
- All-day events won't have duration calculations
Getting Help
- Check the n8n documentation for general n8n questions
- Review HubSpot API docs for invoice-specific issues
- Review Google Calendar API docs for calendar issues
- Contact Workware for help customizing this workflow
Understanding the Workflow
Color to Product Mapping
The key to this workflow is mapping calendar colors to HubSpot products:
- Config node stores the mapping as
colorMappings
- Summarize node groups hours by colorId
- Prepare Line Items uses the mapping to convert colors to product IDs
Example:
- Calendar event with color
11
(red) - Config maps color
11
to "Consulting" - "Consulting" is mapped to HubSpot product ID
12345
- Line item created with product
12345
and quantity = hours
Association Types
HubSpot uses association type IDs to link objects:
- 177: Links invoice to contact (who to bill)
- 179: Links invoice to company (which organization)
- 410: Links line items to invoice (which items belong to this invoice)
These associations ensure the invoice shows up in the right contact and company records.
Date Range Calculation
The workflow uses Luxon (DateTime) to calculate dates:
DateTime.now().minus({ months: 1 }).startOf('month') // First day of last month
DateTime.now().startOf('month') // First day of this month
This ensures you're always billing for complete months.
Best Practices
Consistent Color Usage
- Document your color scheme: Create a reference guide for which color = which service
- Train your team: Make sure everyone uses colors consistently
- Review regularly: Audit your calendar monthly to catch mis-colored events
Review Before Sending
Even with automation, it's good practice to:
- Run the workflow
- Review the created invoice in HubSpot
- Make any manual adjustments if needed
- Then send the invoice to the client
Track Non-Billable Work Separately
- Don't assign colors to non-billable events
- Or, create a separate calendar for internal/non-billable work
- This keeps your billable reporting clean
Set Reminders
- Calendar reminder to review last month's events
- Check for any events that need colors added
- Verify all billable work was logged
Monthly Reconciliation
Compare workflow-generated invoices with:
- Your time tracking system (if separate)
- Expected hours for retainer clients
- Previous month's hours for trends
Security Considerations
- OAuth tokens: Store securely in n8n; never share credentials
- HubSpot access token: Treat like a password; rotate periodically
- Sensitive data: Invoice data contains billing information
- Access control: Limit who can modify this workflow
Next Steps
Once you're comfortable with this workflow:
- Add time tracking integration: Pull hours from Toggl, Harvest, or other tools
- Multi-currency support: Handle clients in different currencies
- Automated invoice sending: Add a node to send invoices via email
- Reporting dashboard: Track monthly revenue, hours by service type
- Client approval workflow: Send invoice drafts for review before finalizing