POST /api/auth/register
- Description: Register a new user.
- Request Body:
{ "username": "string", "email": "string", "password": "string" }
- Response:
{ "message": "User registered successfully", "userId": "string" }
POST /api/auth/login
- Description: Authenticate a user.
- Request Body:
{ "email": "string", "password": "string" }
- Response:
{ "token": "string", "user": { "id": "string", "username": "string", "email": "string" } }
POST /api/auth/logout
- Description: Log out a user.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
{ "message": "Logout successful" }
POST /api/emails/upload
- Description: Upload a bulk email list.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Request Body:
{ "file": "<CSV/Excel file>" }
- Response:
{ "message": "Emails uploaded successfully", "processed": "integer", "duplicates": "integer", "invalid": "integer" }
GET /api/emails
- Description: Retrieve all uploaded emails.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
[ { "email": "string", "category": "string", "status": "valid | duplicate | invalid" } ]
DELETE /api/emails/:emailId
- Description: Delete an email from the list.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
{ "message": "Email deleted successfully" }
POST /api/campaigns
-
Description: Create 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" }
POST
/api/campaigns/preview
-
Description: Generate a preview of an email campaign by replacing placeholders in the template with recipient data..
-
Headers:
- Authorization:
Bearer <token>
- Authorization:
-
Request Body:
{ "template": "string", // Email template containing placeholders (e.g., "{{firstName}}"). "recipientId": "string" // ID of the recipient to use for replacing placeholders. }
-
Response:
- Success(200) { "message": "Email preview generated successfully", "preview": "string" // The email preview with placeholders replaced by recipient data. } - Client Error(400) { "message": "Template and recipient ID are required" } - Not Found(404) { "message": "Recipient not found" } - Server Error(500): { "message": "An error occurred while generating the email preview" }
GET /api/campaigns
- Description: Retrieve 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" }
GET /api/analytics/:campaignId
- Description: Retrieve 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: Retrieve overall email campaign performance.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
{ "totalEmailsSent": "integer", "totalResponses": "integer", "totalBounces": "integer", "totalUnsubscribes": "integer" }
GET /api/compliance
- Description: Retrieve GDPR and CAN-SPAM compliance settings.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Response:
{ "optOutLink": "string", "senderVerification": "boolean" }
PUT /api/compliance
- Description: Update compliance settings.
- Headers:
- Authorization:
Bearer <token>
- Authorization:
- Request Body:
{ "optOutLink": "string", "senderVerification": "boolean" }
- Response:
{ "message": "Compliance settings updated successfully" }
GET /api/email-lists
-
Description: Fetches a paginated list of email records.
-
Headers:
- Authorization:
Bearer <token>
- Authorization:
-
Query Parameters
-
-
page Number 1 The page number to retrieve.
-
limit Number 10 Number of items to fetch per page.
-
Response:
{ "success": true, "data": [ { "id": "integer", "email": "string" }, { "id": "integer", "email": "string" } ], "meta": { "currentPage": 1, "totalPages": 5, "totalItems": 50, "limit": 10 } }
Endpoint:
GET /api/social/linkedin/authorize
Description:
Fetches LinkedIn profile data for a user based on their email address and saves it in the database.
Required Scopes:
To fetch the necessary LinkedIn data, the following OAuth 2.0 scopes are required during the authorization process:
-
openid
:
This scope grants access to the user's LinkedIn ID and basic profile information. -
email
:
This scope grants access to the user's primary email address. -
profile
:
This scope grants access to the user's basic profile information, including first name, last name, headline, and profile picture.
Steps to Use:
-
Register a LinkedIn Application:
- Go to LinkedIn Developer Portal and create an application.
- Note down your
CLIENT_ID
andCLIENT_SECRET
.
-
Set Up Environment Variables:
Add the following variables to your.env
file:LINKEDIN_CLIENT_ID=your_linkedin_client_id LINKEDIN_CLIENT_SECRET=your_linkedin_client_secret LINKEDIN_REDIRECT_URI=your_redirect_uri
-
Obtain Authorization Code:
- Send users to this authorization URL to obtain the code:
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id={LINKEDIN_CLIENT_ID}&redirect_uri={LINKED_URI}&scope=r_liteprofile%20r_emailaddress
- Replace
{LINKEDIN_CLIENT_ID}
and{LINKEDIN_REDIRECT_URI}
with your application’s details.
- Send users to this authorization URL to obtain the code:
-
Exchange Code for Access Token:
This is handled by the backend when theGET
request is sent to/api/social/linkedin/authorize
.
Request Example:
GET /api/social/linkedin/authorize?code=AUTHORIZATION_CODE
Response Example:
{
"sub": "782bbtaQ",
"name": "John Doe",
"given_name": "John",
"family_name": "Doe",
"picture": "https://media.licdn-ei.com/dms/image/C5F03AQHqK8v7tB1HCQ/profile-displayphoto-shrink_100_100/0/",
"locale": "en-US",
"email": "[email protected]",
"email_verified": true
}
Let me know if you'd like to further adjust this or need any additional details!
Endpoint:
GET /api/social/twitter/:username/:userEmail
Description:
Fetches public profile data from Twitter for a given username and email and saves it in the database.
Steps to Use:
-
Create a Twitter Developer Account:
- Go to the Twitter Developer Portal and create a new app.
- Note down your
API_KEY
andAPI_SECRET_KEY
.
-
Set Up Environment Variables:
Add the following variables to your.env
file:TWITTER_API_KEY=your_twitter_api_key TWITTER_API_SECRET_KEY=your_twitter_api_secret_key TWITTER_BEARER_TOKEN=your_twitter_bearer_token
-
Generate Bearer Token:
- Use the Twitter Developer Portal to generate a Bearer Token. This is required for making API calls.
Request Example:
GET /api/social/twitter/johndoe/[email protected]
Response Example:
{
"email": "[email protected]",
"twitterProfile": {
"username": "johndoe",
"bio": "Building awesome web applications.",
"location": "San Francisco, CA",
"followersCount": 1500,
"followingCount": 200
},
"message": "Twitter profile data saved successfully."
}
Endpoint:
POST /api/social/disable
Description:
Disables social media integration for a user and deletes saved LinkedIn and Twitter data.
Request Example:
{
"email": "[email protected]"
}
Response Example:
{
"message": "Social media integration disabled, and data deleted successfully."
}
-
Error Handling:
Both endpoints handle missing or incomplete profile data gracefully and return descriptive error messages.
Example:{ "error": "Twitter profile not found for the given username." }
-
Database Integration:
Fetched data is stored in theSocialMediaSchema
with fields for email, LinkedIn profile, Twitter profile, andupdatedAt
. -
Testing:
Use mock email addresses and usernames to test the API endpoints. Ensure the.env
file is properly configured for LinkedIn and Twitter API access.
Would you like sample code for any of these routes?