8.9 KiB
n8n Integration Guide
Overview
The n8n integration provides a low-code approach to fetch data from multiple providers (Zoho, Salesforce, QuickBooks) through a single unified webhook endpoint in n8n.
Architecture
Backend API → n8n Client → n8n Webhook → Provider APIs (Zoho/Salesforce/etc.)
Benefits
- ✅ Single webhook handles multiple providers
- ✅ Less code maintenance in backend
- ✅ Easy to add new providers in n8n without backend changes
- ✅ Visual workflow management
- ✅ Built-in error handling and retry logic
Setup
1. Environment Variables
Add these to your .env file:
# n8n Configuration
N8N_WEBHOOK_URL=http://localhost:5678
N8N_WEBHOOK_ID=04e677f5-ec57-4772-bf12-96f2610d4b9c
2. Import n8n Workflow
- Open your n8n instance
- Import the workflow from
My_workflow_3 (1).json - The webhook will be automatically created with ID:
04e677f5-ec57-4772-bf12-96f2610d4b9c - Activate the workflow
3. Webhook Endpoint
The n8n webhook URL will be:
POST http://localhost:5678/webhook/04e677f5-ec57-4772-bf12-96f2610d4b9c
API Usage
Authentication
All endpoints require JWT authentication. Include the Authorization header:
Authorization: Bearer <your_jwt_token>
Endpoints
1. Get Supported Providers
GET /api/v1/n8n/providers
Response:
{
"status": "success",
"message": "Supported providers retrieved",
"data": {
"zoho": {
"crm": ["leads", "contacts", "accounts", "deals", "tasks", ...],
"books": ["organizations", "contacts", "customers", ...],
"people": ["employees", "departments", ...],
"projects": ["portals", "projects", "tasks", ...]
},
"salesforce": {
"crm": ["leads", "accounts", "tasks", "opportunities", "events"]
}
},
"timestamp": "2025-10-09T12:00:00.000Z"
}
2. Generic Data Fetch (Any Provider)
GET /api/v1/n8n/data/:provider/:service/:module
Parameters:
provider- zoho, salesforce, intuitservice- crm, books, people, projectsmodule- leads, contacts, accounts, etc.
Query Parameters:
limit(optional) - Number of records (default: 200, max: 1000)page(optional) - Page number (default: 1)offset(optional) - Offset for pagination (default: 0)
Examples:
# Fetch Zoho CRM Leads
GET /api/v1/n8n/data/zoho/crm/leads?limit=100&page=1
# Fetch Salesforce Accounts
GET /api/v1/n8n/data/salesforce/crm/accounts?limit=50
# Fetch Zoho People Employees
GET /api/v1/n8n/data/zoho/people/employees?limit=200
3. Zoho Shorthand Routes
GET /api/v1/n8n/zoho/:service/:module
Examples:
# CRM
GET /api/v1/n8n/zoho/crm/leads
GET /api/v1/n8n/zoho/crm/contacts
GET /api/v1/n8n/zoho/crm/accounts
GET /api/v1/n8n/zoho/crm/deals
# Books
GET /api/v1/n8n/zoho/books/invoices
GET /api/v1/n8n/zoho/books/customers
GET /api/v1/n8n/zoho/books/vendors
# People
GET /api/v1/n8n/zoho/people/employees
GET /api/v1/n8n/zoho/people/departments
# Projects
GET /api/v1/n8n/zoho/projects/portals
GET /api/v1/n8n/zoho/projects/projects
4. Salesforce Shorthand Routes
GET /api/v1/n8n/salesforce/:service/:module
Examples:
GET /api/v1/n8n/salesforce/crm/leads
GET /api/v1/n8n/salesforce/crm/accounts
GET /api/v1/n8n/salesforce/crm/opportunities
GET /api/v1/n8n/salesforce/crm/tasks
GET /api/v1/n8n/salesforce/crm/events
Response Format
All endpoints return data in this format:
{
"status": "success",
"message": "zoho crm leads data fetched successfully",
"data": {
"success": true,
"data": [
{
"id": "123",
"name": "John Doe",
...
}
],
"count": 1,
"metadata": {}
},
"timestamp": "2025-10-09T12:00:00.000Z"
}
Error Responses
{
"status": "error",
"message": "Unsupported combination: zoho/crm/invalid_module",
"errorCode": "N8N_FETCH_ERROR",
"timestamp": "2025-10-09T12:00:00.000Z"
}
Workflow Structure
Input Payload to n8n
The backend sends this payload to the n8n webhook:
{
"body": {
"provider": "zoho",
"service": "crm",
"module": "leads",
"acces_token": "1000.xxxxx",
"instance_url": null
},
"query": {
"per_page": 200,
"page": 1
}
}
Workflow Flow
- Webhook receives the request
- Provider Switch routes based on
provider(zoho, salesforce, intuit) - Service Switch routes based on
service(crm, books, people, projects) - Module Switch routes based on
module(leads, contacts, etc.) - HTTP Request calls the provider API
- Response returns data to backend
Supported Modules
Zoho CRM
leads- Leads datacontacts- Contacts dataaccounts- Accounts datadeals- Deals/Opportunities datatasks- Tasks datapurchase_orders- Purchase Orders (disabled in workflow)sales_orders- Sales Orders (disabled in workflow)invoices- Invoices (disabled in workflow)
Zoho Books
organizations- Organizationscontacts- All contactscustomers- Customer contactsvendors- Vendor contactsaccounts- Bank accountspurchase_orders- Purchase Orderssales_orders- Sales Ordersinvoices- Invoicesbills- Billsexpenses- Expenses
Zoho People
employees- Employee recordsdepartments- Departments (disabled in workflow)timesheets- Timesheets (disabled in workflow)leaves- Leave records (disabled in workflow)attendence- Attendance (disabled in workflow)attendence_entries- Attendance entriesattendence_report- Attendance reportsleave_tracker- Leave balance trackerleaves_data- Leave datagoals_data- Goals dataperformance_data- Performance data (disabled in workflow)
Zoho Projects
portals- Portalsprojects- Projectstasks- Project-specific tasksall_tasks- All tasks across projectstasklists- Task lists for specific projectall_tasklists- All task listsissues- Issuesphases- Project phases
Salesforce CRM
leads- Leads dataaccounts- Accounts datatasks- Tasks dataopportunities- Opportunities dataevents- Events/Meetings datareports- Reports (not yet implemented in workflow)
Code Examples
Using in Your Service
const n8nService = require('./services/n8nService');
// Fetch Zoho CRM Leads
async function getZohoLeads(userId) {
try {
const result = await n8nService.fetchZohoCrmData(
userId,
'leads',
{ limit: 100, page: 1 }
);
console.log('Leads:', result.data);
console.log('Count:', result.count);
} catch (error) {
console.error('Error:', error.message);
}
}
// Fetch Salesforce Accounts
async function getSalesforceAccounts(userId) {
try {
const result = await n8nService.fetchSalesforceCrmData(
userId,
'accounts',
{ limit: 50, offset: 0 }
);
console.log('Accounts:', result.data);
} catch (error) {
console.error('Error:', error.message);
}
}
Using with cURL
# Get your JWT token first
TOKEN="your_jwt_token"
# Fetch Zoho CRM Leads
curl -X GET "http://localhost:3000/api/v1/n8n/zoho/crm/leads?limit=100" \
-H "Authorization: Bearer $TOKEN"
# Fetch Salesforce Opportunities
curl -X GET "http://localhost:3000/api/v1/n8n/salesforce/crm/opportunities?limit=50" \
-H "Authorization: Bearer $TOKEN"
Error Handling
The integration includes comprehensive error handling:
- Token Validation - Checks if user has authenticated with the provider
- Module Validation - Validates provider/service/module combination
- n8n Timeout - 60-second timeout for webhook calls
- Logging - All requests and errors are logged
Adding New Providers
To add a new provider (e.g., QuickBooks):
-
Update n8n workflow:
- Add new switch case in "Provider Switch"
- Create service and module switches
- Add HTTP request nodes
-
Update backend mapper:
- Add modules to
N8nMapper.getSupportedModules()
- Add modules to
-
Add environment variables (if needed):
QUICKBOOKS_CLIENT_ID=xxx QUICKBOOKS_CLIENT_SECRET=xxx -
No other backend code changes required! 🎉
Performance Considerations
- Default timeout: 60 seconds
- Default page size: 200 records
- Maximum page size: 1000 records
- Use pagination for large datasets
- n8n workflow can be scaled horizontally
Troubleshooting
Common Issues
-
"n8n workflow execution failed"
- Check if n8n is running
- Verify webhook URL and ID in .env
- Check n8n workflow logs
-
"Authentication not found"
- User must authenticate via OAuth first
- Use
/api/v1/users/oauth/callbackendpoint
-
"Unsupported combination"
- Check supported modules via
/api/v1/n8n/providers - Verify module name spelling
- Check supported modules via
-
Timeout errors
- Reduce page size
- Check provider API status
- Increase timeout in n8n client
License
MIT