Skip to content

Email api

Endpoint: /api/v1/email/send

Method: POST

Description: Sends an email to a specified recipient

Request Body (JSON):

{
"subject": "Welcome to the course!",
"from": "[email protected]",
"html": "<p>This is an example!</p>"
}

Response:

{
"success": true,
"message": "Email sent successfully"
}

JavaScript (Node.js):

const axios = require('axios');
async function sendEmail() {
try {
const response = await axios.post('https://buisnesstools.com/api/v1/email/send', {
subject: 'Welcome to the course!',
html: '<p>This is an example!</p>'
}, {
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
});
console.log('Email sent:', response.data);
} catch (error) {
console.error('Error sending email:', error.response.data);
}
}

Python:

import requests
def send_email():
url = 'https://buisnesstools.com/api/v1/email/send'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
data = {
'subject': 'Welcome to the course!',
'from': '[email protected]',
'html': '<p>This is an example!</p>'
}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
print('Email sent:', response.json())
else:
print('Error:', response.json())

cURL:

Terminal window
curl -X POST https://buisnesstools.com/api/v1/email/send \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"subject": "Welcome to the course!",
"from": "[email protected]",
"html": "<p>This is an example!</p>"
}'

PHP:

<?php
$url = 'https://buisnesstools.com/api/v1/email/send';
$data = [
'to' => '[email protected]',
'subject' => 'Welcome to the course!',
'from' => '[email protected]',
'html' => '<p>This is an example!</p>'
];
$options = [
'http' => [
'header' => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json'
],
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$result = json_decode($response, true);
if ($result['success']) {
echo "Email sent: " . $result['message'];
} else {
echo "Error: " . $result['error'];
}
?>

Endpoint: /api/v1/email/templates

Method: GET

Description: Retrieves a list of available email templates

Response:

{
"success": true,
"error": "",
"data": [
{
"id": "1",
"name": "Welcome Email",
"body": "Welcome to {{course_name}}!",
"variables":["course_name"],
"created_at": "2024-01-15T10:30:00Z"
},
{
"id": "2",
"name": "Course Completion",
"body": "Congratulations on completing {{course_name}}!",
"variables":["course_name"],
"created_at": "2024-01-20T14:15:00Z"
}
],
"message": "Templates retrieved successfully"
}

JavaScript (Node.js):

const axios = require('axios');
async function listTemplates() {
try {
const response = await axios.get('https://buisnesstools.com/api/v1/email/template', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
console.log('Templates:', response.data.data);
} catch (error) {
console.error('Error fetching templates:', error.response.data);
}
}

Python:

import requests
def list_templates():
url = 'https://buisnesstools.com/api/v1/email/template'
headers = {
'Authorization': 'Bearer YOUR_API_KEY'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
templates = response.json()['data']
for template in templates:
print(f"Template: {template['name']} (ID: {template['id']})")
else:
print('Error:', response.json())

cURL:

Terminal window
curl -X GET https://buisnesstools.com/api/v1/email/templates \
-H "Authorization: Bearer YOUR_API_KEY"

Endpoint: /api/v1/email/template

Method: POST

Description: Sends an email using a pre-defined template

Request Body (JSON):

{
"template_id": "template_123",
"variables": {
"student_name": "John Doe",
"course_name": "Mastering React"
}
}

Response:

{
"success": true,
"message": "email sent successfully"
}

JavaScript (Node.js):

const axios = require('axios');
async function sendTemplateEmail() {
try {
const response = await axios.post('https://buisnesstools.com/api/v1/email/send-template', {
template_id: 'template_123',
variables: {
student_name: 'John Doe',
course_name: 'Mastering React'
}
}, {
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
});
console.log('Template email sent:', response.data);
} catch (error) {
console.error('Error sending template email:', error.response.data);
}
}

Python:

import requests
def send_template_email():
url = 'https://buisnesstools.com/api/v1/email/send-template'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
data = {
'template_id': 'template_123',
'variables': {
'student_name': 'John Doe',
'course_name': 'Mastering React'
}
}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
print('Template email sent:', response.json())
else:
print('Error:', response.json())

cURL:

Terminal window
curl -X POST https://buisnesstools.com/api/v1/email/send-template \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"template_id": "template_123",
"variables": {
"student_name": "John Doe",
"course_name": "Mastering React"
}
}'