n8n Integration
Msghub integrates seamlessly with n8n. Use HTTP Request nodes to send messages and webhook triggers to receive delivery events.
Setup
Get Your API Key
- Go Settings → API Keys
- Copy your API key (starts with
mk_live_)
Create n8n Workflow
- Log in to n8n
- Create new workflow
- Add HTTP Request node
- Configure as shown below
Send Messages
HTTP Request Node
Add an HTTP Request node to send messages:
Configuration:
- Method: POST
- URL: https://your-msghub.com/api/v1/messages/send
- Headers:
- X-API-Key: mk_live_...
- Content-Type: application/json
- Body: JSON with message details
Send SMS
{
"channel": "sms",
"to": "{{ $json.phone }}",
"body": "Hi {{ $json.name }}, your order has shipped!"
}
Send WhatsApp
{
"channel": "whatsapp",
"to": "{{ $json.phone }}",
"templateId": "order_confirmation",
"parameters": {
"name": "{{ $json.name }}",
"orderId": "{{ $json.orderId }}"
}
}
Send Email
{
"channel": "email",
"to": "{{ $json.email }}",
"subject": "Your order has shipped",
"body": "<h1>Order Confirmation</h1><p>Your order has shipped!</p>"
}
Receive Delivery Events
Webhook Trigger
Add a Webhook trigger to receive delivery events:
Configuration:
- Method: POST
- Path: /msghub-webhook (or any path)
Msghub will POST events to your webhook:
{
"event": "message.delivered",
"messageId": "msg_abc123",
"channel": "sms",
"to": "+919876543210",
"status": "delivered",
"deliveredAt": "2024-04-08T10:30:05Z"
}
Configure Webhook in Msghub
- Go Settings → Webhooks
- Click Add Webhook
- Enter:
- Event: message.delivered
- URL: Your n8n webhook URL
- Click Save
Example Workflows
Shopify Order → WhatsApp Confirmation
Trigger: Shopify → New Order
↓
HTTP Request: Get order details
↓
HTTP Request: Send WhatsApp confirmation via Msghub
↓
Wait: 2 hours
↓
HTTP Request: Check delivery status
↓
If not delivered:
HTTP Request: Send SMS fallback
Google Sheets → Email Campaign
Trigger: Google Sheets → New Row
↓
HTTP Request: Send email via Msghub
↓
Wait: 24 hours
↓
HTTP Request: Check open status
↓
If opened:
HTTP Request: Send follow-up email
Webhook → Multi-Channel Message
Trigger: Webhook (from your app)
↓
HTTP Request: Send SMS via Msghub
↓
HTTP Request: Send WhatsApp via Msghub
↓
HTTP Request: Send Email via Msghub
↓
End
API Reference
Send Message
POST /api/v1/messages/send
Headers:
X-API-Key: mk_live_...
Content-Type: application/json
Body:
{
"channel": "sms|whatsapp|email|rcs|instagram|web_chat",
"to": "+919876543210",
"body": "Message text",
"templateId": "optional_template_id",
"parameters": {
"key": "value"
}
}
Response:
{
"messageId": "msg_abc123",
"status": "queued"
}
Check Message Status
GET /api/v1/messages/msg_abc123
Headers:
X-API-Key: mk_live_...
Response:
{
"messageId": "msg_abc123",
"channel": "sms",
"to": "+919876543210",
"status": "delivered",
"deliveredAt": "2024-04-08T10:30:05Z"
}
Create Contact
POST /api/v1/contacts
Headers:
X-API-Key: mk_live_...
Content-Type: application/json
Body:
{
"name": "Rahul",
"phone": "+919876543210",
"email": "rahul@example.com",
"tags": ["vip", "newsletter"]
}
Response:
{
"contactId": "contact_123",
"name": "Rahul",
"phone": "+919876543210"
}
Best Practices
Error Handling
Add error handling to your workflows:
HTTP Request: Send message
↓
If error:
HTTP Request: Log error to your system
↓
Send notification: "Message failed"
Rate Limiting
Msghub allows 100 requests per second. For bulk operations:
Loop: For each contact
↓
HTTP Request: Send message
↓
Wait: 100ms (to avoid rate limit)
Logging
Log all messages for audit trail:
HTTP Request: Send message
↓
HTTP Request: Log to your database
↓
HTTP Request: Log to analytics
Troubleshooting
401 Unauthorized
- Check API key — Is it correct?
- Check header — Is it "X-API-Key"?
400 Bad Request
- Check JSON — Is it valid?
- Check required fields — channel, to, body?
- Check phone format — Must be E.164 (+919876543210)
429 Too Many Requests
- Rate limit exceeded — Add delays between requests
- Use batch API — Send multiple messages in one request