HubSpot–Odoo Connector for Automated Email Import

Bringing HubSpot email history into Odoo, linked to the right contacts, automatically

This case study covers the development of a custom hubspot_odoo_connector module for Odoo, built to import a client's HubSpot email history into Odoo and keep it linked to the correct contacts. The module fetches emails from HubSpot's API on a schedule, queues them for processing and creates fully-populated mail.mail records in Odoo including sender, recipient, status, direction and the associated contact.

HubSpot–Odoo Connector for Automated Email Import

1. Business Challenge

The client's email communication history lived in HubSpot, disconnected from the contact and loan records already managed in Odoo. They needed that email history pulled into Odoo automatically, correctly matched to existing contacts, filtered to a relevant date range and reliable enough to run unattended without creating duplicates, timing out on large volumes, or importing emails for contacts that don't exist in Odoo.

2. Solution & Approach

The connector was built and refined over several iterations directly with client feedback, moving from a basic fetch script to a production-ready, scheduled sync:

  • Reviewed HubSpot's API and email properties, identifying the required fields for import: subject, status, associated contact ID and direction and confirmed contact data in Odoo was correctly linked to HubSpot IDs using a restored database backup.
  • Built the hubspot_odoo_connector module, including a new hubspot.queue model to hold paginated email data with its own views and menu and extended mail.mail with HubSpot-specific fields (subject, status, sender, recipient, direction, associated contact ID).
  • Configured two scheduled actions: a HubSpot Email Fetcher that pulls emails via a Bearer token in pages of 100, capped at 50 pages per run with the next-page link stored for the following run to avoid timeouts; and a Queue Processor that runs every minute and creates the corresponding mail.mail record from each queued job.
  • Diagnosed a gap where the HubSpot API response didn't return the email "from" and "to" addresses and some contacts were missing in Odoo; worked with the client via Jira to get the corrected API call, then implemented HubSpot's associations API to fetch the related contact and company details for each email.
  • Added a date-based filter so only emails created after January 1, 2023 are fetched and only when an associated contact already exists in Odoo avoiding unnecessary records.
  • Fixed a pagination issue where re-running the fetch could restart from the beginning; the logic now resumes correctly from the last batch and prevents duplicate email records.
  • Hardened the _process_queue method to validate HubSpot data before processing matching contacts by HubSpot contact ID, mapping HubSpot email statuses to Odoo's mail states and improving error handling around invalid field references.
  • Updated the module so HubSpot emails are created under the correct company (Redguard) rather than the default company, verified locally against the Loans-V18-3 backup and pushed the change to the Loans-V18-3 branch.
  • Validated the end-to-end workflow with the client in a live demo and documented findings in Jira including that the Fetch Email scheduled action needs to be run manually to generate new queues, while the Queue Processor runs automatically.

3. Key Technical Highlights

  • Paginated, resumable email fetching from HubSpot with automatic duplicate prevention.
  • Queue-based processing architecture (hubspot.queue) decoupling fetch from record creation for reliability.
  • Contact-matching by HubSpot contact ID before creating any email, avoiding orphaned records.
  • Date-range filtering and company-specific email creation to match client requirements.
  • HubSpot-to-Odoo status mapping and enriched mail.mail records with full metadata.

4. Outcome

The result is a working HubSpot email import connector for Odoo that reliably fetches, filters and links historical and ongoing HubSpot emails to the correct Odoo contacts running on a schedule, resistant to duplication and timeouts and validated end-to-end with the client.

5. Technology Stack

Odoo 18 (Mail, Scheduled Actions), HubSpot REST API (Emails & Associations), Python (requests).

Need a Similar Odoo Integration

Talk to our Odoo team about connecting HubSpot, or any other third-party platform, with your Odoo records.

WhatsApp