Projects
Loading projects...
API Documentation
Authentication
All API requests require authentication using an API key. Include the API key in the request headers:
Authorization: Bearer YOUR_API_KEY X-Project-ID: your-project-id
Base URL
http://localhost:4000/api/v1→
https://messaging.aivatarlabs.ai/api/v1
Send Email
POST
/messages/email
Description: Send an email message
Request Body:
{
"to": "user@example.com", // Required: string or array
"subject": "Hello", // Required: string
"html": "<h1>Hello!</h1>", // Optional: HTML content
"text": "Hello!", // Optional: Plain text
"cc": "cc@example.com", // Optional: string or array
"bcc": "bcc@example.com", // Optional: string or array
"from": "sender@example.com", // Optional: string
"replyTo": "reply@example.com", // Optional: string
"priority": 5, // Optional: 1-10 (default: 5)
"campaignId": "campaign-123" // Optional: string
}
Response (202 Accepted):
{
"success": true,
"messageId": "msg-123",
"jobId": "job-456",
"channel": "email",
"status": "queued",
"recipient": "user@example.com",
"priority": 5,
"estimatedDelivery": "2024-06-24T10:00:00Z",
"createdAt": "2024-06-24T09:59:00Z"
}
Example cURL:
curl -X POST http://localhost:4000/api/v1/messages/email \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "X-Project-ID: your-project-id" \
-H "Content-Type: application/json" \
-d '{
"to": "user@example.com",
"subject": "Hello",
"html": "<h1>Hello World!</h1>"
}'
Get Message Status
GET
/messages/:id/status
Description: Get delivery status and tracking information for a message
Response (200 OK):
{
"success": true,
"message": {
"id": "msg-123",
"channel": "email",
"status": "sent",
"recipient": "user@example.com",
"subject": "Hello",
"priority": 5,
"provider": "resend",
"providerMessageId": "resend-abc-123",
"timestamps": {
"created": "2024-06-24T09:59:00Z",
"sent": "2024-06-24T09:59:15Z"
},
"metrics": {
"queueTime": 5,
"deliveryTime": 10
},
"events": [
{
"type": "queued",
"timestamp": "2024-06-24T09:59:00Z"
},
{
"type": "sent",
"provider": "resend",
"timestamp": "2024-06-24T09:59:15Z"
}
]
}
}
Example cURL:
curl http://localhost:4000/api/v1/messages/msg-123/status \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "X-Project-ID: your-project-id"
Get Message Events
GET
/messages/:id/events
Description: Get all events for a specific message
Response (200 OK):
{
"success": true,
"messageId": "msg-123",
"events": [
{
"type": "queued",
"timestamp": "2024-06-24T09:59:00Z",
"metadata": {}
},
{
"type": "sent",
"provider": "resend",
"timestamp": "2024-06-24T09:59:15Z",
"metadata": {
"providerMessageId": "resend-abc-123"
}
}
],
"count": 2
}
Health Check
GET
/health
Description: Check service health (no authentication required)
Response (200 OK):
{
"status": "ok",
"version": "1.0.0",
"uptime": 12345,
"timestamp": "2024-06-24T10:00:00Z",
"services": {
"database": "connected",
"redis": "connected"
}
}
Error Responses
| Status Code | Error Type | Description |
|---|---|---|
| 400 | Validation Error | Invalid request data |
| 401 | Authentication Error | Invalid or missing API key |
| 404 | Not Found | Resource not found |
| 429 | Rate Limit | Too many requests |
| 500 | Server Error | Internal server error |
Error Response Format:
{
"success": false,
"error": "Error type",
"message": "Detailed error message",
"statusCode": 400
}
SDK Usage (TypeScript/JavaScript)
import { MessagingClient } from '@aivatar/messaging-sdk';
const client = new MessagingClient({
apiKey: 'YOUR_API_KEY',
projectId: 'your-project-id',
baseUrl: 'http://localhost:4000',
});
// Send email
const response = await client.sendEmail({
to: 'user@example.com',
subject: 'Hello',
html: '<h1>Hello World!</h1>',
});
// Check status
const status = await client.getStatus(response.messageId);
// Get events
const events = await client.getEvents(response.messageId);