A production-ready webhook-driven data connector service that receives requests from the CheckD Data Connector Gateway, authenticates with Zoho CRM using OAuth 2.0, extracts merchant contact data, and stores it in Dataswyft Wallets with comprehensive error handling and user-friendly error pages.
- π Production API Endpoint -
/connect
endpoint for Data Connector Gateway integration - π Application Token Authentication - Validates and processes Application tokens from the gateway
- π§ Email-Based Contact Search - Searches Zoho CRM contacts by merchant email
- πΎ Smart Namespace Storage - Test/production separation with automatic detection
- π User-Friendly Error Pages - Professional error pages for different failure scenarios
- π Callback Integration - Returns status and record IDs via callback URLs
- π§ͺ Comprehensive Testing - Full end-to-end test suite with error page validation
git clone <repository-url>
cd zoho-crm-data-connector
npm install
Create your environment file:
cp .env.example .env
Configure your credentials in .env
:
# Zoho CRM OAuth Configuration (Self-Client)
ZOHO_CRM_CLIENT_ID=your_client_id_here
ZOHO_CRM_CLIENT_SECRET=your_client_secret_here
ZOHO_CRM_REFRESH_TOKEN=your_refresh_token_here
# Data Connector Configuration (Required for production)
DS_APPLICATION_ID=oi-s-zohocrmdataconnector
DS_NAMESPACE=zoho_crm
DS_DATA_PATH=contacts
CONNECTOR_PORT=8080
CALLBACK_URL=https://example.com/callback
# Test-Only Configuration (Only needed for running test scripts)
DATASWIFT_API_URL=https://your-wallet-instance.hubat.net
DATASWIFT_USERNAME=your_username
DATASWIFT_PASSWORD=your_password
NODE_ENV=development
- Go to Zoho API Console
- Create a new application β Select "Self Client"
- Configure scopes:
ZohoCRM.modules.contacts.ALL
- Note your
Client ID
andClient Secret
- In API Console β "Generate Code" tab
- Select scopes:
ZohoCRM.modules.contacts.ALL
- Generate authorization code (expires in 3 minutes)
- Add your Client ID and Client Secret to
.env
file first - Run the test suite to exchange authorization code for refresh token:
npm test
When prompted, enter your authorization code. The test will validate your setup and display the refresh token to copy to your .env
file.
Import sample contacts to your Zoho CRM:
-
Sample contacts included:
[email protected]
- TechCorp Solutions (US)[email protected]
- Global Finance Ltd (UK)[email protected]
- InnovateStart Inc (Australia)
-
Import to Zoho CRM:
- Upload
test_data/zoho_sample_data.csv
to your Contacts module - Map CSV columns to Zoho CRM fields
- Upload
# Production mode
npm start
# Development mode
npm run dev
Server runs on http://localhost:8080
(or CONNECTOR_PORT
)
Query Parameters:
token
(required) - JWT token containing PDA URL and application IDcallback_url
(required) - URL to redirect after completiondata
(required) - JSON object containing merchant emailrequest_id
(required) - Request identifier for tracking
Example Request:
GET /connect?token=eyJhbGc...&callback_url=https://checkd.io/api/callback&data={"email":"[email protected]"}&request_id=req_123456
Response Flow:
- Immediate Response - 200 OK with processing status
- Async Processing - Validates JWT, searches Zoho CRM, stores data
- Callback Response - Success/failure status with record IDs or error page URL
The connector provides user-friendly error pages for different scenarios:
- π Contact Not Found (404) -
/error?type=EMAIL_NOT_FOUND
- π Authentication Failed (401) -
/error?type=INVALID_TOKEN
- π Zoho CRM Error (401) -
/error?type=OAUTH_FAILURE
β οΈ Service Error (500) -/error?type=API_ERROR
- π Invalid Request (400) -
/error?type=INVALID_DATA
npm test
The test suite validates the complete /connect
endpoint workflow including success scenarios, error handling, JWT token validation, and error page functionality.
- Gateway Request β
/connect
endpoint with JWT token - JWT Validation β Extract PDA URL and validate expiration
- Contact Search β Find merchant in Zoho CRM by email
- Data Transform β Convert to Dataswyft wallet format
- Storage β Save to appropriate namespace (test/production)
- Callback β Send success status with record ID
- Error Detection β Invalid token, missing email, API failure
- Error Page Generation β Create user-friendly error page
- Callback β Send failure status with error page URL for user redirection
{
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", // JWT with PDA URL
callback_url: "https://checkd.io/api/callback",
data: "{\"email\":\"[email protected]\"}", // Merchant email
request_id: "req_123456"
}
{
"namespace": "zoho_crm", // or "test" for testing
"endpoint": "/crm/v8/Contacts/search",
"data": {
"id": "6899019000000603062",
"created_at": "2025-07-16T12:34:51-04:00",
"source": {
"provider": "zoho_crm",
"version": "v8",
"module": "Contacts"
},
"content": {
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe",
"company": "Example Corp",
"phone": "+1-555-0123",
"jobtitle": "CEO",
"country": "United States",
// ... additional fields
},
"metadata": {
"sync_timestamp": "2025-07-30T22:15:30.123Z",
"connector_version": "1.0.0",
"schema_version": "1.0"
}
}
}
src/
βββ server.js # Main Express server with /connect endpoint
βββ auth/
β βββ oauth-client.js # Zoho CRM OAuth 2.0 client
β βββ token-manager.js # Token caching and refresh
β βββ jwt-token-generator.js # JWT utilities
βββ connectors/
β βββ zoho-crm-connector.js # CRM API client with field optimization
β βββ contact-search.js # Email-based contact search
β βββ data-mapper.js # Data transformation
βββ storage/
β βββ dataswyft-wallet-client.js # Dataswyft Wallet API client
βββ test/
βββ test-connect-endpoint.js # Main endpoint test suite
βββ run-connect-test.js # Test runner with server management
βββ test-connection.js # OAuth authentication test
βββ import-contact-to-wallet.js # Individual contact import test
curl http://localhost:8080/health
Response:
{
"status": "healthy",
"version": "1.0.0",
"timestamp": "2025-07-30T22:15:30.123Z"
}
- Set
NODE_ENV=production
for production namespace usage - Ensure
ZOHO_CRM_REFRESH_TOKEN
is valid and secure
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY src/ ./src/
EXPOSE 8080
CMD ["npm", "start"]
EMAIL_NOT_FOUND
(404) - Contact not found in Zoho CRMINVALID_TOKEN
(401) - JWT token invalid or expiredOAUTH_FAILURE
(401) - Zoho CRM authentication failedAPI_ERROR
(500) - General service errorINVALID_DATA
(400) - Invalid request parameters
- Non-retryable: Email not found, invalid tokens
- Retryable: OAuth failures, API errors, network issues
- Automatic: Exponential backoff for transient failures
- OAuth token acquisition: < 1 second
- Contact search: < 1 second
- Data transformation: < 100ms
- Wallet storage: < 2 seconds
- Total processing time: < 5 seconds
- Limited field extraction from Zoho CRM
- In-memory token caching
- Namespace separation for test/production
- Connection pooling for external APIs
- β JWT token validation with expiration checking
- β OAuth refresh tokens stored securely as environment variables
- β Access tokens never persisted to disk
- β HTTPS-only communication with external APIs
- β Input validation for all request parameters
- β Error page sanitization to prevent XSS
"Token has expired"
- Regenerate authorization code in Zoho API Console
- Run
npm test
to get new refresh token
"Contact not found"
- Verify email exists in Zoho CRM Contacts
- Check test data import was successful
- Ensure contact has required fields populated
"Tests failing"
- Verify all environment variables are set
- Check Zoho CRM refresh token is valid
- Ensure Dataswyft wallet credentials are correct
Enable detailed logging:
LOG_LEVEL=debug npm start
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature
- Make changes and add tests
- Run test suite:
npm test
- Submit pull request
[Your License Here]