App Sections
App Sections provide a way to decouple your email templates from your codebase. Instead of hardcoding email template IDs in your application code, you create named sections that represent different email triggers in your application (like "forgot password" or "welcome email"). These sections can then be connected to email templates through the Spotent interface.
Benefits
- Change email templates without deploying code changes
- A/B test different email variations
- Manage email content through the Spotent interface
- Keep your codebase clean and maintainable
For example, instead of hardcoding template IDs in your code:
// ❌ Old way: Hardcoding template IDs
const welcomeTemplateId = "template_abc123"; // Requires code changes to update
// ✅ New way: Using app sections
const WELCOME_SECTION = "section_xyz789"; // Templates can be changed in Spotent
App Section HTML Endpoint
Get HTML for an email template associated with an app section with variable replacement.
Endpoint
POST /api/v1/section/{sectionId}
Authentication
All requests require a Bearer token in the Authorization header:
Authorization: Bearer your_api_token
Request
URL Parameters
sectionId
(required): The public ID of your app section
Body
Send a JSON object containing your variable values. The required variables depend on the email template attached to your section:
{
"FIRST_NAME": "John",
"COMPANY_NAME": "Acme Inc"
// ... other variables as needed
}
Response
Success Response (200 OK)
- Content-Type:
text/html
- Body: Raw HTML string of the email template associated with your app section, with variables replaced
Important Note About Response Handling
When consuming this API in Javascript, you'll need to properly handle the HTML string encoding. Here's the recommended way:
const res = await fetch("https://api.spotent.co/v1/section/your_section_id", {
method: "POST",
headers: {
"Accept": "text/html",
"Content-Type": "application/json",
Authorization: "Bearer your_api_token",
},
body: JSON.stringify({
FIRST_NAME: "John",
}),
});
const data = await res.text();
const rawHtml = Buffer.from(data, "utf-8").toString();
// rawHtml is now ready to be used
Error Responses
| Status | Code | Description |
| ------ | ----------------- | ------------------------------------------ |
| 400 | MISSING_ID | Section ID is required |
| 400 | INVALID_JSON | Request body must be valid JSON |
| 400 | MISSING_VARIABLES | One or more required variables are missing |
| 401 | MISSING_AUTH | Authorization header is required |
| 401 | INVALID_AUTH | Invalid or inactive API token |
| 404 | SECTION_NOT_FOUND | App section not found |
| 404 | EMAIL_NOT_FOUND | No email template connected to section |
| 500 | RENDER_ERROR | Failed to render email template |
| 500 | INTERNAL_ERROR | Unexpected server error |
Error Response Format
{
"error": {
"status": 400,
"title": "Missing Variables",
"detail": "Required variables are missing from the request",
"code": "MISSING_VARIABLES",
"data": {
"missingVariables": ["FIRST_NAME", "COMPANY_NAME"]
}
}
}
Usage Limits
- Each successful HTML export consumes 1 credit from your organization's balance