A production-ready backend microservice to integrate with HubSpot CRM. Sync contacts, deals, and companies, handle webhooks, and access synced data via REST APIs.
- Authentication: Secure HubSpot API key integration
- Data Sync: Automatic sync of contacts, deals, and companies
- Webhook Handling: Receive and process real-time HubSpot events
- REST API: Clean and documented endpoints
- Error Handling: Exponential backoff and rate-limit support
- Database: PostgreSQL with TypeORM
- Logging: Structured logging with Winston
- TypeScript: Full type safety
- Node.js 18+
- PostgreSQL 15+
- HubSpot Personal Access Key
git clone <your-repo-url>
cd HubSpot_Integration
npm installCopy .env.example to .env and update the values:
PORT=3000
NODE_ENV=development
DB_HOST=localhost
DB_PORT=5432
DB_USER=harsh
DB_PASSWORD=1234@Harsh
DB_NAME=HubspotCRM
HUBSPOT_API_KEY=your-hubspot-api-key
HUBSPOT_BASE_URL=https://api.hubapi.com
WEBHOOK_SECRET=your-webhook-secret
BASE_URL=http://localhost:3000Local PostgreSQL:
CREATE DATABASE HubspotCRM;If PostgreSQL is running in Docker:
docker exec -it mypostgres psql -U harsh -d HubspotCRM# Build TypeScript
npm run build
# Development
npm run dev
# Production
npm startServer runs at http://localhost:3000.
GET /api/healthPOST /api/sync # Sync all entities
POST /api/sync/contacts # Sync contacts
POST /api/sync/deals # Sync deals
POST /api/sync/companies # Sync companiesGET /api/contacts?limit=50&offset=0&email=test@example.com
GET /api/contacts/:idGET /api/deals?stage=qualifiedtobuy&minAmount=1000
GET /api/deals/:idGET /api/companies?industry=Technology
GET /api/companies/:idPOST /api/webhook # Receive events
GET /api/webhooks # List received events
GET /api/webhook-subscriptions # List subscriptions
POST /api/webhook-subscriptions # Create subscription
DELETE /api/webhook-subscriptions/:id # Delete subscription
β οΈ Webhook events and HubSpot UI screenshots are attached for reference. Note: Donβt forget to create subscriptions for Contacts, Deals, and other relevant objects in HubSpot to ensure all events are captured correctly.
- Register via API
curl -X POST http://localhost:3000/api/webhook-subscriptions \
-H "Content-Type: application/json" \
-d '{
"eventType": "contact.creation",
"webhookUrl": "https://your-domain.com/api/webhook"
}'-
Register via HubSpot UI HubSpot β Settings β Integrations β Private Apps β Webhooks β Add your webhook URL
-
Security Set
WEBHOOK_SECRETin.envand configure HubSpot to use the same secret.
src/
βββ config/ # Config (DB, logger)
βββ controllers/ # Request handlers
βββ entities/ # TypeORM entities
βββ middleware/ # Express middleware
βββ routes/ # API routes
βββ services/ # Business logic (HubSpot sync)
βββ index.ts # Entry point
Highlights:
- Idempotent updates using
hubspotId - Exponential backoff for API retries
- Structured logging with Winston
- Centralized error handling middleware
- Rate-limiting protection
npm test
npm run test:watch
Shows sample webhook and Hubspot events received in the service.
Shows the Private App & Webhooks configuration in HubSpot.
- Database issues: Verify PostgreSQL is running locally or via Docker
- Webhook issues: Ensure URL is publicly accessible & check
GET /api/webhooks - API errors: Confirm HubSpot API key and check rate limits
MIT
Build by Harsh