The email campaign automation feature allows users to:
Create and manage email templates. Schedule email campaigns and automate follow-ups. Fetch detailed campaign statistics for performance analysis. This feature is designed to streamline email marketing efforts by providing a user-friendly interface and robust automation tools.
Key Features: Template Management: Easily design and manage email templates. Campaign Scheduling: Schedule one-time or recurring campaigns with precise control. Follow-Ups: Automatically send follow-ups based on recipient behavior. Analytics: Monitor campaign performance, including open rates, click-through rates, and conversions. Add Attachments: Can add attachments in templates, so as to send in mails.
- POST-
/api/templates
- Description: Creates a new email template.
- Request Body:
{
"name": "Welcome Email",
"subject": "Welcome to Our Service!",
"body": "<html>Your custom HTML here</html>"
}
If file is attached then body must be of type multipart/form-data and the key for attachment is 'file'
- Response:
{
"id": "template_id",
"message": "Template created successfully."
}
- GET-
/api/templates
- Description: Retrieves a list of all email templates.
- Response:
{
"id": "template_id",
"name": "Welcome Email",
"subject": "Welcome to Our Service!"
}
- POST-
/api/campaigns
- Description: Creates a new email campaign.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Request Body:
[
{
"name": "string",
"emails": ["string"],
"template": "string",
"schedule": "ISO_8601 string"
}
]
- Response:
{
"message": "Campaign created successfully",
"campaignId": "string"
}
- GET -
/api/campaigns
- Description: Retrieves all campaigns.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
[
{
"campaignId": "string",
"name": "string",
"emailsSent": "integer",
"status": "pending | ongoing | completed"
}
]
PUT /api/campaigns/:campaignId
- Description: Update a campaign.
- Headers:
- Authorization:
Bearer <token>
-
- Request Body:
{ "name": "string", "emails": ["string"], "template": "string", "schedule": "ISO_8601 string" }
- Authorization:
- Response:
{ "message": "Campaign updated successfully" }
-
POST-
/api/campaigns/schedule
-
Description: Schedules an email campaign to be sent at a specified time.
-
Headers:
-
Authorization:
Bearer <token>
-
Request Body:
{
"name": "string",
"emailListId": "string",
"schedule": "ISO_8601 string"
}
- Response: -201 Created: Campaign scheduled successfully.
{
"message": "Campaign scheduled successfully.",
"campaign": {
"campaignId": "string",
"name": "string",
"emailListId": "string",
"schedule": "ISO_8601 string"
}
}
- 400 Bad Request: Missing required fields or invalid data.
{
"message": "Missing required fields."
}
- 500 Internal Server Error: Unexpected server error.
{
"message": "Internal server error."
}
- GET-
/api/campaigns/scheduled
- Description: Retrieves all scheduled email campaigns.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response: -200 OK: Returns a list of all scheduled campaigns.
[
{
"campaignId": "string",
"name": "string",
"emailListId": "string",
"scheduledAt": "ISO_8601 string",
"status": "string"
}
]
- 400 Bad Request: Invalid request.
{
"message": "Invalid request."
}
- 500 Internal Server Error: Unexpected server error.
{
"message": "Internal server error."
}
- POST-
/api/campaigns/{campaign_id}/follow-ups
- Description : Adds a follow-up to an existing campaign.
- Request Body:
{
"delay_hours": 48,
"follow_up_template_id": "template_id"
}
- Response:
{
"message": "Follow-up added successfully."
}
- GET -
/api/analytics/:campaignId
- Description: Retrieves analytics for a specific campaign.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
{
"openRate": "percentage",
"clickThroughRate": "percentage",
"responseRate": "percentage",
"bounces": "integer",
"unsubscribes": "integer"
}
- GET-
/api/analytics
- Description: Retrieves overall performance data for all email campaigns.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
{
"totalEmailsSent": "integer",
"totalResponses": "integer",
"totalBounces": "integer",
"totalUnsubscribes": "integer"
}
-Example: SendGrid -Sign up at SendGrid. -Generate an API key in the dashboard. -Add the API key to your application's configuration file:
-SENDGRID_API_KEY=your_api_key
# Test the connection using the following command:
```bash
curl -X POST https://api.sendgrid.com/v3/mail/send \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"personalizations": [{"to": [{"email": "[email protected]"}]}],
"from": {"email": "[email protected]"},
"subject": "Test Email",
"content": [{"type": "text/plain", "value": "Hello, world!"}]
}'
- Clone the Repository:
git clone https://github.com/your-username/sponsohive-backend.git cd sponsohive-backend
- Install Dependencies::
npm install
- Set Up Environment Variables: Create a .env file in the root directory and configure the following::
SENDGRID_API_KEY=your_key AWS_ACCESS_KEY_ID=your_key AWS_SECRET_ACCESS_KEY=your_key
- Run the Application::
npm run dev
-
Use 2 spaces for indentation.
-
Naming Conventions
-
Use camelCase for variables/functions and PascalCase for classes.
-
RESTful API naming (e.g., /api/campaigns/:id/analytics).
-
Constants in UPPER_SNAKE_CASE.
-
Function Design
-
Ensure single responsibility (one task per function).
-
Use object parameters for functions with >3 arguments.
-
Example: scheduleCampaign({ name, emails, templateId, time }).
-
Store sensitive data (e.g., SENDGRID_API_KEY) in .env.
-
Validate and sanitize inputs (e.g., emails, template IDs).
-
Use consistent error handling (e.g., middleware for server errors).
-
Use appropriate HTTP status codes (200, 201, 400, 500).
-
Return descriptive responses: { "message": "Campaign created successfully" }.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name
). - Commit your changes (
git commit -m 'Add your feature here'
). - Push to the branch (
git push origin feature/your-feature-name
). - Open a pull request.