Description
n8n-nodes-zalo-oa-refresh

An n8n community node for Zalo Official Account token refresh automation. This node helps you automatically refresh Zalo OA access tokens before they expire, ensuring your integrations stay connected.
Features
- 🔄 Automatic Token Refresh: Refresh Zalo OA access tokens before they expire
- ✅ Token Status Check: Check if current tokens are still valid
- ⏰ Smart Scheduling: Only refresh when needed (< 2 hours until expiry)
- 🔐 Multi-Layer Storage: Workflow static data + database + environment variables
- 🛡️ Robust Error Handling: Graceful fallbacks when storage methods fail
- 📊 Detailed Logging: Comprehensive execution logs with ✅/❌ status indicators
- 🔧 Production Ready: Multiple backup storage methods ensure reliability
Installation
Via n8n Community Nodes
- Go to your n8n instance
- Navigate to Settings → Community Nodes
- Click Install a Community Node
- Enter:
n8n-nodes-zalo-oa-refresh - Click Install
Via npm
# Install globally
npm install -g n8n-nodes-zalo-oa-refresh
# Or install in your n8n project
npm install n8n-nodes-zalo-oa-refresh
Credentials
Zalo Official Account API
This node requires a Zalo Official Account API credential with the following fields:
| Field | Description | Required |
|---|---|---|
| App ID | Your Zalo OA App ID from Developer Console | ✅ |
| Secret Key | Your Zalo OA Secret Key | ✅ |
| Access Token | Current access token (auto-updated) | ❌ |
| Refresh Token | Token used to refresh access token | ✅ |
| Token Expires At | ISO date when token expires | ❌ |
Getting Credentials
- Go to Zalo Developer Console
- Create or select your Official Account app
- Get your App ID and Secret Key
- Obtain initial Refresh Token through OAuth flow
- Configure the credential in n8n
Nodes
Zalo OA Refresh Token
Main node for token management operations.
Operations
Refresh Token
- Calls Zalo API to refresh access token
- Returns new access token and refresh token
- Calculates new expiration time
Check Token Status
- Checks if current token is still valid
- Returns time until expiry
- Indicates if refresh is needed
Example Workflow
{
"name": "Zalo OA Token Refresh Automation",
"nodes": [
{
"name": "Schedule Every 23 Hours",
"type": "n8n-nodes-base.scheduleTrigger",
"parameters": {
"rule": {
"interval": [{"field": "hours", "hoursInterval": 23}]
}
}
},
{
"name": "Check Token Status",
"type": "n8n-nodes-zalo-oa-refresh.zaloOaRefreshToken",
"parameters": {
"operation": "checkStatus"
}
},
{
"name": "Refresh if Needed",
"type": "n8n-nodes-base.if",
"parameters": {
"conditions": {
"boolean": [{
"value1": "={{$json.should_refresh}}",
"value2": true
}]
}
}
},
{
"name": "Refresh Token",
"type": "n8n-nodes-zalo-oa-refresh.zaloOaRefreshToken",
"parameters": {
"operation": "refreshToken"
}
}
]
}
API Reference
Zalo OAuth Endpoint
The node calls this Zalo API endpoint:
POST https://oauth.zaloapp.com/v4/oa/access_token
Content-Type: application/x-www-form-urlencoded
secret_key: YOUR_SECRET_KEY
refresh_token=YOUR_REFRESH_TOKEN&
app_id=YOUR_APP_ID&
grant_type=refresh_token
Response Format
{
"access_token": "new_access_token_here",
"refresh_token": "new_refresh_token_here",
"expires_in": "90000"
}
Scheduling Recommendations
- Every 23 hours: Safe interval to refresh before 25-hour expiry
- Check before refresh: Always check token status first
- Handle failures: Implement retry logic and alerts
- Monitor logs: Review execution history regularly
Security Best Practices
- ✅ Store credentials securely in n8n credential manager
- ✅ Use environment variables for sensitive data
- ✅ Enable webhook authentication where possible
- ✅ Monitor token usage and refresh patterns
- ❌ Never log or expose tokens in plain text
- ❌ Don't commit credentials to version control
Troubleshooting
Common Issues
Token refresh fails
- Check if secret key is correct
- Verify refresh token hasn't expired
- Ensure network connectivity to Zalo API
Node not found in n8n
- Restart n8n after installation
- Check community nodes are enabled
- Verify installation completed successfully
Credentials not working
- Double-check App ID and Secret Key
- Test with Zalo API directly using curl
- Verify OAuth flow was completed correctly
Debug Tips
- Enable detailed logging in n8n
- Test with "Check Token Status" first
- Use n8n's execution logs to trace issues
- Check Zalo Developer Console for API limits
Development
Local Development
# Clone repository
git clone https://github.com/yourusername/n8n-nodes-zalo-oa-refresh.git
cd n8n-nodes-zalo-oa-refresh
# Install dependencies
pnpm install
# Build
pnpm build
# Watch mode
pnpm dev
Testing
# Run linter
pnpm lint
# Format code
pnpm format
# Run tests
pnpm test
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
Changelog
v1.5.2 (2025-08-22)
🔧 Major Token Storage Improvements
- ✅ Multi-layer storage system: Tokens now saved to workflow static data, database, AND environment variables
- ✅ Robust error handling: Graceful fallbacks when any storage method fails
- ✅ Fixed database issues: Proper SQLite syntax with UUID generation for n8n variables table
- ✅ Enhanced logging: Clear ✅/❌ status indicators for each storage method
- ✅ Production reliability: Never fails completely – always has backup storage
- ✅ Priority retrieval: Smart token fetching with fallback hierarchy
Technical Fixes
- Fixed SQL syntax from PostgreSQL to SQLite (
INSERT OR REPLACEinstead ofON CONFLICT) - Added proper ID field handling for n8n variables table
- Improved database connection handling with fallback methods
- Enhanced TypeScript type safety for workflow static data
- Better error isolation – single storage failure doesn't break entire operation
v1.5.1 and earlier
- Initial release with basic token refresh functionality
- Zalo OA API integration
- Basic credential management
License
Support
Made with ❤️ for the n8n community