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

FeatureGoogle 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
Get Started with a free trial of n8n Cloud
Sign up for n8n Cloud to start building your automated workflows
Learn more

How It Works

This workflow follows these steps:

  1. Retrieve calendar events from the previous month
  2. Filter for billable events (those with a colorId)
  3. Calculate duration of each event in hours
  4. Summarize hours by service type (color)
  5. Create HubSpot invoice with contact/company associations
  6. Add line items for each service type with calculated hours

Step 1: Download and Import Workflow

1.1 Download Workflow File

  1. Click the workflow card below to visit the workflow details page
  2. Click the Download button to download the workflow JSON file
  3. 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.

Google CalendarHubSpotInvoicingAutomationScheduled

1.2 Import Workflow to n8n

  1. Open your n8n instance
  2. Create a new workflow
  3. Click the ... menu (three dots) in the top right
  4. Select Import from File...
  5. Choose the downloaded workflow JSON file
  6. 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:

  1. Open Google Calendar
  2. Decide which colors represent which services (e.g., red = consulting, blue = development)
  3. Apply colors to your billable events:
    • Create or edit an event
    • Click the color picker (bucket icon)
    • Select a color
  4. Note down the mapping (you'll need this for HubSpot configuration)

2.2 Find Color IDs

Google Calendar assigns numeric IDs to colors:

  1. The easiest way is to run the workflow once with test data
  2. Look at the colorId field in the calendar event data
  3. Common color IDs:
    • 1 = Lavender
    • 2 = Sage
    • 3 = Grape
    • 4 = Flamingo
    • 5 = Banana
    • 6 = Tangerine
    • 7 = Peacock
    • 8 = Graphite
    • 9 = Blueberry
    • 10 = Basil
    • 11 = Tomato

Step 3: Set Up HubSpot

3.1 Create HubSpot Private App

  1. Go to your HubSpot account
  2. Navigate to SettingsIntegrationsPrivate Apps
  3. Click Create a private app
  4. Give it a name (e.g., "n8n Calendar Integration")
  5. Under Scopes, select:
    • crm.objects.contacts.read
    • crm.objects.companies.read
    • crm.objects.invoices.write
    • crm.objects.line_items.write
  6. Click Create app
  7. 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:

  1. Go to SalesProducts in HubSpot
  2. Create a product for each service type:
    • Click Create product
    • Enter product name (e.g., "Consulting Hours")
    • Set price per unit (hourly rate)
    • Save
  3. 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

  1. Open a contact in HubSpot
  2. Look at the URL: https://app.hubspot.com/contacts/HUBID/record/0-1/CONTACTID
  3. Note the CONTACTID
  4. Open the associated company
  5. Look at the URL: https://app.hubspot.com/contacts/HUBID/record/0-2/COMPANYID
  6. Note the COMPANYID

3.4 Find Your Hub ID

  1. Go to HubSpot SettingsAccount SetupAccount Defaults
  2. Your Hub ID is shown at the top
  3. 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

  1. In your n8n workflow, click on the Get many events node
  2. Under Credential to connect with, click the dropdown
  3. Select Create New Credential
  4. Choose Google Calendar OAuth2 API
  5. Fill in the credential details:
    • Name: "Google Calendar"
    • Follow the OAuth setup wizard to connect your Google account
  6. Click Save
  7. Authorize n8n to access your Google Calendar

4.2 Add HubSpot Bearer Auth Credential

  1. Click on the Create Invoice node
  2. Under Credential to connect with, click the dropdown
  3. Select Create New Credential
  4. Choose HTTP Bearer Auth
  5. Fill in the credential details:
    • Name: "HubSpot Private App"
    • Token: Paste your HubSpot private app access token
  6. Click Save

4.3 Attach Credentials to All Nodes

The HubSpot credential needs to be attached to:

  • Create Invoice
  • Add Line Items

To attach:

  1. Click on each node
  2. Under Credential to connect with, select your "HubSpot Private App" credential
  3. 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.

  1. Double-click the Config node to open the code editor
  2. 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"
  }
};
  1. Click Save

5.2 Update Calendar ID

  1. Double-click the Get many events node
  2. Under Calendar, select your Google Calendar
  3. If you don't see your calendar:
    • Click the refresh icon
    • Or, find your calendar ID in Google Calendar settings
  4. 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:

  1. Go to Google Calendar
  2. 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
  3. Make sure events have the colors configured in your Config node

6.2 Manual Test Run

  1. Click Execute Workflow (play button) at the bottom
  2. 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
  3. Check for errors in any node

6.3 Verify Invoice in HubSpot

  1. Go to HubSpot → SalesInvoices
  2. Find the newly created invoice
  3. 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

  1. Delete the Manual trigger node (or disconnect it)
  2. Add a Schedule Trigger node:
    • Click + to add a new node
    • Search for "Schedule Trigger"
    • Add it to the workflow
  3. Connect it to the Config node

7.2 Configure Monthly Schedule

  1. Double-click the Schedule Trigger node
  2. 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)
  3. 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

  1. Click the Active toggle at the top of the workflow
  2. 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)

  1. Duplicate the entire workflow
  2. Rename it (e.g., "Invoice - Client B")
  3. Update the Config node with client B's data
  4. Each client gets their own automated workflow

Option 2: Add Client Selection Logic

  1. Add a node after Config that determines which client
  2. Use an IF node to route to different invoice creation branches
  3. More complex but keeps everything in one workflow

Change Date Range

By default, the workflow processes the previous month. To customize:

  1. Edit the Config node
  2. 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:

  1. Edit the Create Invoice node
  2. 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:

  1. Edit the Filter node
  2. 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:

  1. Add a Send Email node or Slack node at the end
  2. Map invoice data to the message:
    • Invoice ID
    • Total hours
    • Line item breakdown
  3. 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

Understanding the Workflow

Color to Product Mapping

The key to this workflow is mapping calendar colors to HubSpot products:

  1. Config node stores the mapping as colorMappings
  2. Summarize node groups hours by colorId
  3. 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:

  1. Run the workflow
  2. Review the created invoice in HubSpot
  3. Make any manual adjustments if needed
  4. 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:

  1. Add time tracking integration: Pull hours from Toggl, Harvest, or other tools
  2. Multi-currency support: Handle clients in different currencies
  3. Automated invoice sending: Add a node to send invoices via email
  4. Reporting dashboard: Track monthly revenue, hours by service type
  5. Client approval workflow: Send invoice drafts for review before finalizing
GuideGoogle CalendarHubSpotInvoicingAutomationn8n