Creating a Campaign
This endpoint creates a new email campaign in the system that stores details such as:
- Campaign name
- Subject line
- Content (HTML or text)
- Associated recipient lists
Later, campaigns can be sent using the Send Campaign Endpoint.
Endpoint
POST /campaign/create
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer <your-api-key> | ✅ Yes |
Content-Type | application/json | ✅ Yes |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | String | ✅ Yes | A friendly name for the campaign. |
subject | String | ✅ Yes | The subject line of the emails. |
content | String | ❌ Optional | The HTML or text content of the campaign. |
recepientList | Array of Strings | ❌ Optional | IDs of recipient lists to associate with the campaign. |
Examples
Request
- JavaScript
- Python
- PHP
- cURL
const response = await fetch("https://api.basicsengage.com/api/v0/dev/campaign/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <your-api-key>"
},
body: JSON.stringify({
name: "Weekly Newsletter",
subject: "Our Latest Updates",
content: "<h1>Hello Subscribers</h1>",
recepientList: ["640cfa8d1", "640cfa8d2"]
})
});
const data = await response.json();
console.log(data);
import requests
url = "https://api.basicsengage.com/api/v0/dev/campaign/create"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <your-api-key>"
}
data = {
"name": "Weekly Newsletter",
"subject": "Our Latest Updates",
"content": "<h1>Hello Subscribers</h1>",
"recepientList": ["640cfa8d1", "640cfa8d2"]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
</TabItem>
<TabItem value="csharp" label="C#">
```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
private static readonly HttpClient client = new HttpClient();
static async Task Main()
{
var url = "https://api.basicsengage.com/api/v0/dev/campaign/create";
var apiKey = "Bearer <your-api-key>";
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Authorization", apiKey);
var data = new
{
name = "Weekly Newsletter",
subject = "Our Latest Updates",
content = "<h1>Hello Subscribers</h1>",
recepientList = new string[] { "640cfa8d1", "640cfa8d2" }
};
var json = System.Text.Json.JsonSerializer.Serialize(data);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
<?php
$url = "https://api.basicsengage.com/api/v0/dev/campaign/create";
$headers = [
"Content-Type: application/json",
"Authorization: "Bearer <your-api-key>"
];
$data = [
"name" => "Weekly Newsletter",
"subject" => "Our Latest Updates",
"content" => "<h1>Hello Subscribers</h1>",
"recepientList" => ["640cfa8d1", "640cfa8d2"]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
curl -X POST "https://api.basicsengage.com/api/v0/dev/campaign/create" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-api-key>" \
-d '{
"name": "Weekly Newsletter",
"subject": "Our Latest Updates",
"content": "<h1>Hello Subscribers</h1>",
"recepientList": ["640cfa8d1", "640cfa8d2"]
}'
Responses
- 🟢 200
- 🔴 400
- 🔴 401
- 🔴 500
{
"status": "success",
"data": {
"campaign": {
"_id": "64a55f123...",
"name": "Holiday Sale",
"subject": "Exclusive 50% Off",
"content": "<p>Happy Holidays!</p>"
}
}
}
{
"status": "error",
"error": "Missing required field: 'name'."
}
{
"status": "error",
"message": "Invalid API Key"
}
{
"status": "error",
"message": "Internal server error. Please try again later."
}