Prerequisites
Before running the Marketing Events Sync script, ensure you have the following:- Node.js installed (version 14 or higher recommended)
- A HubSpot account with access to:
- Marketing Events API (
/marketing/v3/marketing-events/) - CRM Objects API (
/crm/v3/objects/deals)
- Marketing Events API (
- A valid HubSpot Private Access Token (PAT) with appropriate scopes
File Structure
The project consists of two main files:events.js
The main synchronization script that:- Fetches marketing events from HubSpot’s Marketing Events API
- Filters events created on the current day
- Creates corresponding records in a custom CRM object (deals)
- Handles duplicate detection and error recovery
test.js
A local test script with mock data that allows you to:- Test the sync logic without making API calls
- Validate pipeline mapping and deal stage assignment
- Verify event filtering and date parsing
Installation
1. Download the Script
Clone or download the repository to your local machine:events.js and test.js files directly.
2. Install Dependencies
The script uses Node.js built-infetch API (Node.js 18+). If you’re using an older version, install node-fetch:
events.js to import it:
Configuration
Setting Up Your Access Token
The script currently has a placeholder token atevents.js:2:
Option 1: Environment Variable (Recommended)
Replace the hardcoded token with an environment variable:Option 2: Direct Replacement (Testing Only)
For quick local testing, replace the placeholder with your actual token:API Endpoints
The script connects to two HubSpot APIs (events.js:3-4):
Pipeline Mapping
The script includes a pipeline-to-dealstage mapping (events.js:205-213):
- HubSpot Settings → Objects → Deals → Pipelines
Organizer Mapping
The script maps event organizers to valid HubSpot values (events.js:230-266). Update the mapping logic to match your organization’s structure:
Verification
Verify your setup by running the test script:Next Steps
Testing the Sync
Learn how to test the sync with mock data and validate results
Troubleshooting
Common issues and how to resolve them