Skip to content

Harshsharma836/HubBridge-HubSpot-Integration

Repository files navigation

HubSpot Integration Service πŸš€

A production-ready backend microservice to integrate with HubSpot CRM. Sync contacts, deals, and companies, handle webhooks, and access synced data via REST APIs.


✨ Features

  • 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

πŸ“‹ Prerequisites

  • Node.js 18+
  • PostgreSQL 15+
  • HubSpot Personal Access Key

πŸ› οΈ Setup

1. Clone and Install

git clone <your-repo-url>
cd HubSpot_Integration
npm install

2. Environment Variables

Copy .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:3000

3. Database Setup

Local PostgreSQL:

CREATE DATABASE HubspotCRM;

If PostgreSQL is running in Docker:

docker exec -it mypostgres psql -U harsh -d HubspotCRM

4. Build and Run

# Build TypeScript
npm run build

# Development
npm run dev

# Production
npm start

Server runs at http://localhost:3000.


πŸ“‘ API Endpoints

Health Check

GET /api/health

Sync

POST /api/sync           # Sync all entities
POST /api/sync/contacts  # Sync contacts
POST /api/sync/deals     # Sync deals
POST /api/sync/companies # Sync companies

Contacts

GET /api/contacts?limit=50&offset=0&email=test@example.com
GET /api/contacts/:id

Deals

GET /api/deals?stage=qualifiedtobuy&minAmount=1000
GET /api/deals/:id

Companies

GET /api/companies?industry=Technology
GET /api/companies/:id

Webhooks

POST /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.


πŸ” Webhook Setup

  1. 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"
  }'
  1. Register via HubSpot UI HubSpot β†’ Settings β†’ Integrations β†’ Private Apps β†’ Webhooks β†’ Add your webhook URL

  2. Security Set WEBHOOK_SECRET in .env and configure HubSpot to use the same secret.


πŸ—οΈ Architecture

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

πŸ§ͺ Testing

npm test
npm run test:watch

πŸ“Έ Screenshots

Webhook and Hubspot Events

Screenshot 2025-11-21 014333
Screenshot 2025-11-21 104931
Screenshot 2025-11-21 112113

Shows sample webhook and Hubspot events received in the service.

HubSpot UI

Screenshot 2025-11-21 111634
Screenshot 2025-11-21 111655
Screenshot 2025-11-21 112246

Shows the Private App & Webhooks configuration in HubSpot.


πŸ“š HubSpot Documentation


πŸ› Troubleshooting

  • 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

πŸ“„ License

MIT

πŸ‘€ Author

Build by Harsh

About

POC for Seamlessly connect, sync, and automate your HubSpot contacts, deals, and workflows

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages