Base URL
All API endpoints are served from the Express server running on port 3001 by default.OAuth Endpoints
Manage HubSpot OAuth authentication flow.Initiate OAuth Flow
main/server/src/oauth.ts:46
Flow
- Generates random state token for CSRF protection
- Stores state in memory with timestamp
- Builds authorization URL with:
client_idfrom environmentredirect_urifrom environmentscopefrom environmentstatetoken
- Redirects user to HubSpot
Environment Variables Required
HubSpot application client ID
OAuth callback URL (must match HubSpot app settings)
Space-separated OAuth scopes (e.g., “forms”)
Response
OAuth Callback
main/server/src/oauth.ts:53
Query Parameters
Authorization code from HubSpot
CSRF protection token (must match stored state)
Request Flow
- Validates
codeandstateparameters - Verifies state token exists in store
- Exchanges code for tokens via POST to
https://api.hubapi.com/oauth/v1/token - Stores tokens in memory with expiration
- Redirects to frontend URL or returns JSON
Token Exchange Request
Success Response (with FRONTEND_URL)
Success Response (without FRONTEND_URL)
Always
true on successHubSpot portal (account) ID
Error Responses
Invalid or missing state/code parameters
Token exchange failed or server error
Token Storage
Tokens are stored in an in-memory Map:Check OAuth Status
main/server/src/oauth.ts:118
Response
Whether any OAuth tokens are stored
Logout
main/server/src/oauth.ts:123
Response
Always
trueConfirmation message
Forms API Endpoints
Fetch HubSpot forms and their schemas.List Forms
main/server/src/forms.ts:126
Authentication
Requires valid OAuth token in server’s token store.Response
Array of form objects
HubSpotForm Type
Unique form identifier
Form display name
Creation timestamp (milliseconds)
Last update timestamp (milliseconds)
Error Responses
Not connected to HubSpot or no valid token
Failed to fetch from HubSpot API
HubSpot API Called
Get Form Schema
main/server/src/forms.ts:168
Path Parameters
The HubSpot form ID
Authentication
Requires valid OAuth token in server’s token store.Response
Normalized form schema
Debug information about the form structure
FormSchema Type
Form identifier
Form name
Array of field definitions
FieldSchema Type
Field identifier (unique within form)
Display label for the field
Field type (text, email, phone, number, textarea, select, dropdown, radio, checkbox, multiple_checkboxes, etc.)
Whether the field is required
Available options for select/radio/checkbox fields
Validation rules
FieldOption Type
Display text for the option
Submitted value for the option
Error Responses
Missing formId parameter
Not connected to HubSpot
Failed to fetch form details from HubSpot
HubSpot API Called
Field Normalization
The endpoint normalizes HubSpot’s field structure:- Extracts fields from
formFieldGroups,fieldGroups, orfieldsarrays - Normalizes field types from
type,fieldType, orinputType - Normalizes labels from
labelorlabelText - Normalizes options from
optionsorchoicesarrays - Filters out invalid fields (missing name)
- Ensures consistent option structure (label + value)
Health Check
main/server/src/index.ts:27
Response
CORS Configuration
The server allows CORS requests from:http://localhost:5173(default Vite dev server)- Any
*.trycloudflare.comsubdomain - Origin header matches allowed origins
main/server/src/index.ts:10-24
Error Handling
All endpoints follow consistent error response format:Common Status Codes
Request successful
Redirect (OAuth flow)
Invalid request parameters
Not authenticated or session expired
Server error or external API failure
Token Management
Tokens are stored in an in-memory Map with the following structure:- Tokens are lost on server restart
- No automatic token refresh implemented
- Single portal support (last connected portal)
- No expiration checking on token usage
- Implement persistent token storage (database, Redis)
- Add automatic token refresh logic
- Support multiple portals per user
- Check token expiration before use
- Implement proper session management
