Prerequisites
Before you begin, ensure you have:Node.js
Node.js 16+ installed on your system
HubSpot Account
Access to a HubSpot account with Marketing Hub
Private App Access
Permissions to create a HubSpot Private App
Custom Object
A custom deal object or access to the Deals API
Setup Authentication
Create a HubSpot Private App
Navigate to Settings → Integrations → Private Apps in your HubSpot account and create a new private app.
You’ll need these scopes:
crm.objects.marketing_events.readcrm.objects.deals.writecrm.objects.deals.read
Copy the access token
Once created, copy the access token. You’ll use this to authenticate API requests.
Configure Pipeline Mapping
The script maps pipeline values from event custom properties to deal stages. Here’s the default mapping fromevents.js:
events.js
Running the Script
Test with mock data
First, test the script logic locally using the provided test file:This runs the sync logic with mock event data and displays the expected output without making real API calls.
Example output
Example output
Update API endpoint
Modify the
CUSTOM_OBJECT_API constant in events.js to point to your custom object:events.js
Run the live sync
Execute the sync script to process real Marketing Events:The script will:
- Fetch all Marketing Events from your HubSpot account
- Filter events created today
- Check for existing records
- Create new deal records for today’s events
The script runs once when executed. For continuous syncing, schedule it with cron or a task scheduler.
Understanding the Sync Logic
Here’s how the key functions work together:1. Fetch Events with Pagination
events.js
2. Filter by Today’s Date
events.js
3. Check for Duplicates
events.js
4. Map Pipeline and Stage
events.js
5. Create the Deal
events.js
Troubleshooting
401 Unauthorized Error
401 Unauthorized Error
No Events Found Today
No Events Found Today
If
todayEvents: 0 is returned:- Verify that events were actually created today in HubSpot
- Check the
hs_createdatefield format in your events - Review the date filtering logic and timezone settings
Validation Error on Create
Validation Error on Create
If you see
VALIDATION_ERROR when creating deals:- A record with the same name already exists (the script checks for this)
- Required fields are missing from the custom object
- Property values don’t match allowed options (e.g., organizer values)
Rate Limiting
Rate Limiting
If you’re syncing large volumes:
- Add delays between API calls
- Reduce the batch size
- Consider upgrading your HubSpot API limits
Next Steps
Configure Mappings
Customize pipeline and organizer mappings for your setup
Understand Filtering
Learn how date filtering handles different timestamp formats
View All Functions
Explore the complete function reference
Troubleshooting Guide
Resolve common issues and errors