Please refer to the Github Repo https://github.com/h3110Fr13nd/vectorshift-hubspot-integration and clone it to move forward.
This guide will help you set up and run the VectorShift Integration Assessment project. The project consists of a React frontend, FastAPI backend, and Redis for session management.
Prerequisites
- Node.js (v18 or higher)
 - Python (v3.10 or higher)
 - Redis
 - Docker and Docker Compose (optional, for containerized setup)
 
Configuration Setup
- 
Create and configure the root level environment file:
cp .env.example .envConfigure in root
.env:FRONTEND_ENV=development # Environment for frontend (development/production) FRONTEND_PORT=3000 # Port for frontend service BACKEND_PORT=8000 # Port for backend service REDIS_PORT=6379 # Port for Redis service - 
Create and configure the frontend environment file:
cd frontend cp .env.example .envConfigure in frontend
.env:REACT_APP_API_URL=http://localhost:8000 # Backend API URL - 
Create and configure the backend environment file:
cd backend cp .env.example .envConfigure in backend
.env:# Redis Configuration REDIS_HOST=redis # Use 'redis' for docker-compose, 'localhost' for local setup REDIS_PORT=6379 # Should match root REDIS_PORT # OAuth Credentials AIRTABLE_CLIENT_ID=your_client_id AIRTABLE_CLIENT_SECRET=your_client_secret NOTION_CLIENT_ID=your_client_id NOTION_CLIENT_SECRET=your_client_secret HUBSPOT_CLIENT_ID=your_client_id HUBSPOT_CLIENT_SECRET=your_client_secret # OAuth Redirect URIs (adjust ports if changed in root .env) AIRTABLE_REDIRECT_URI=http://localhost:8000/oauth/airtable/callback NOTION_REDIRECT_URI=http://localhost:8000/oauth/notion/callback HUBSPOT_REDIRECT_URI=http://localhost:8000/oauth/hubspot/callback 
Important Notes:
- For Docker setup, use 
REDIS_HOST=redis - For local setup, use 
REDIS_HOST=localhost - Ensure all redirect URIs match your OAuth provider settings
 - Keep sensitive credentials secure and never commit .env files to version control
 - When changing ports in root 
.env, update corresponding service configurations and redirect URIs 
Option 1: Running with Docker Compose
- 
Build and start all services:
docker compose up --build - 
Access the application:
- Frontend: http://localhost:80 (or your configured FRONTEND_PORT)
 - Backend: ${process.env.REACT_APP_API_URL} (or your configured BACKEND_PORT)
 - Redis: localhost:6379 (or your configured REDIS_PORT)
 
 
Option 2: Running Locally
Backend Setup
- 
Navigate to the backend directory:
cd backend - 
Create and activate a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate - 
Install dependencies:
pip install -e . - 
Start Redis server:
redis-server - 
Start the FastAPI server:
uvicorn main:app --reload 
Frontend Setup
- 
Navigate to the frontend directory:
cd frontend - 
Install dependencies:
npm install - 
Start the development server:
npm start 
Verifying the Setup
- 
Check if the frontend is running:
- Open http://localhost:3000 in your browser
 - You should see the integration selection interface
 
 - 
Check if the backend is running:
- Open ${process.env.REACT_APP_API_URL}/health
 - You should see 
{"status": "healthy"} 
 - 
Test Redis connection:
- Redis should be running on port 6379
 - The backend should be able to connect to Redis for session management
 
 
Troubleshooting
- 
Port Conflicts
- If ports are already in use, modify them in your .env files
 - Remember to update redirect URIs if you change the backend port
 
 - 
Redis Connection Issues
- For local setup: ensure Redis is running (
redis-server) - For Docker: ensure the Redis service is up (
docker-compose ps) 
 - For local setup: ensure Redis is running (
 - 
Environment Variables
- Double-check all credentials in .env files
 - Ensure redirect URIs match your setup
 - Verify REDIS_HOST is set correctly (‘redis’ for Docker, ‘localhost’ for local)
 
 
Integration Testing
To test the integrations:
- 
Set up developer accounts:
- Create a HubSpot developer account
 - (Optional) Create Notion and Airtable developer accounts
 
 - 
Configure OAuth credentials:
- Add OAuth credentials to your backend .env file
 - Ensure redirect URIs are correctly configured in the provider dashboards
 
 - 
Test the OAuth flow:
- Click “Connect to HubSpot” in the UI
 - Complete the OAuth authorization
 - Verify the connection status updates
 
 
Additional Notes
- The frontend runs in development mode with hot reloading enabled
 - The backend uses FastAPI’s automatic reload capability
 - Redis persistence is enabled in Docker setup
 - Frontend is served through Nginx in Docker setup
 
HubSpot Integration Architecture
The HubSpot integration is designed to be highly extensible and maintainable through a declarative field mapping system. This architecture allows for easy addition of new HubSpot API endpoints and object types without changing the core logic.
Key Features
- 
Declarative Field Mappings: Field mappings are defined in a configuration object (
HUBSPOT_FIELD_MAPPINGS) rather than hardcoded in the processing logic. - 
Parallel API Fetching: Multiple HubSpot API endpoints are queried concurrently for better performance.
 - 
Flexible Data Extraction: Supports multiple data extraction patterns:
- Direct field mapping
 - Nested field access
 - Multiple alternative paths
 - Custom transformations
 - Chained transformations
 
 
Adding New HubSpot API Endpoints
To add a new HubSpot API endpoint, follow these steps:
- Add the endpoint to the 
object_typesdictionary inget_items_hubspot(): 
object_types = {
    "crm": [
        'objects/contacts',
        'objects/companies',
        'objects/deals',
        'your_new_endpoint'  # Add your new endpoint here
    ],
    "cms": [
        'pages/site-pages',
    ]
}- Define the field mapping in 
HUBSPOT_FIELD_MAPPINGS: 
HUBSPOT_FIELD_MAPPINGS = {
    'your_new_endpoint': {
        'id': ['id'],  # Direct field mapping
        'type': lambda data: 'YourType',  # Function mapping
        'name': ['properties', 'name'],  # Nested field mapping
        'creation_time': [  # Multiple alternative paths
            ['createdAt'],
            ['properties', 'createdate']
        ],
        'url': {  # Field with transformation
            'paths': [['properties', 'domain']],
            'transform': 'url_domain'
        },
        'complex_field': {  # Chained transformations
            'paths': [['field1'], ['field2']],
            'transform': 'first_transform',
            'then': {
                'paths': [null],  # Result from previous transform
                'transform': 'second_transform'
            }
        }
    }
}Field Mapping Options
- Direct Field Access:
 
'id': ['id']  # Maps to object.id- Nested Field Access:
 
'name': ['properties', 'firstname']  # Maps to object.properties.firstname- Multiple Alternative Paths:
 
'creation_time': [
    ['createdAt'],
    ['properties', 'createdate']
]  # Tries each path in order until a value is found- Function Mapping:
 
'type': lambda data: 'Contact'  # Returns constant value- Transformation with Single Path:
 
'url': {
    'paths': [['properties', 'domain']],
    'transform': 'url_domain'
}- Transformation with Multiple Inputs:
 
'name': {
    'paths': [['properties', 'firstname'], ['properties', 'lastname']],
    'transform': 'join_names'
}Available Transformations
bool_inverse: Inverts a boolean valueurl_domain: Prepends ‘https://’ to a domainurl_email: Prepends ‘mailto:’ to an emailjoin_names: Combines first and last names with a space
To add a new transformation, add it to the apply_transform function in utils.py:
def apply_transform(value, transform=None):
    # ...existing transforms...
    elif transform == 'your_new_transform':
        return your_transform_logic(value)Best Practices
- 
Field Validation: Always handle missing or null values gracefully in your field mappings.
 - 
Transformation Reuse: Create reusable transformations for common data patterns.
 - 
Documentation: Document the expected data structure when adding new endpoints.
 - 
Testing: Test your field mappings with sample API responses before deployment.
 - 
Extensibility: This architecture ensures that adding new HubSpot API endpoints is a matter of configuration rather than code changes, making the system highly maintainable and extensible.
 
Links : TODO
Tags :
Date : 9th April, Wednesday, 2025, (Wikilinks: 9th April, April 25, April, 2025. Wednesday)
Category : Others