Email Template HTML Endpoint
Get HTML for an email template with variable replacement.
Endpoint
POST /api/v1/email/{templateId}
Authentication
All requests require a Bearer token in the Authorization header:
Authorization: Bearer your_api_token
Request
URL Parameters
templateId
(required): The public ID of your email template
Body
Send a JSON object containing your variable values. The required variables depend on your template:
{
"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 your email template 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/email/your_template_id", {
method: "POST",
headers: {
"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 | Template 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 | EMAIL_NOT_FOUND | Template not found |
| 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
- Your organization can continue making requests even with a negative credit balance
Email Template Metadata Endpoint
Get metadata information about an email template, including its variables and other attributes.
Endpoint
GET /api/v1/email/{templateId}/metadata
Authentication
All requests require a Bearer token in the Authorization header:
Authorization: Bearer your_api_token
Request
URL Parameters
templateId
(required): The public ID of your email template
Body
No body required for this endpoint.
Response
Success Response (200 OK)
- Content-Type:
application/json
- Body: JSON object containing template metadata
{
"data": {
"type": "email_template",
"id": "template_public_id",
"attributes": {
"title": "Welcome Email",
"subject": "Welcome to Our Platform",
"variables": ["FIRST_NAME", "COMPANY_NAME"],
"createdAt": "2024-01-20T10:00:00.000Z",
"updatedAt": "2024-01-21T15:30:00.000Z"
},
"links": {
"self": "/api/v1/email/template_public_id/metadata",
"html": "/api/v1/email/template_public_id"
}
}
}
Response Fields
type
: Always "email_template"id
: The public ID of the templateattributes
:title
: The template's display namesubject
: The email subject linevariables
: Array of variable names used in the templatecreatedAt
: ISO 8601 timestamp of template creationupdatedAt
: ISO 8601 timestamp of last template update
links
:self
: URL to this metadata endpointhtml
: URL to get the rendered HTML version
Error Responses
| Status | Code | Description |
| ------ | --------------- | -------------------------------- |
| 400 | MISSING_ID | Template ID is required |
| 401 | MISSING_AUTH | Authorization header is required |
| 401 | INVALID_AUTH | Invalid or inactive API token |
| 404 | EMAIL_NOT_FOUND | Template not found |
| 500 | INTERNAL_ERROR | Unexpected server error |
Error Response Format
{
"error": {
"status": 400,
"title": "Missing ID",
"detail": "Email template ID is required",
"code": "MISSING_ID"
}
}
Usage
This endpoint is useful for:
- Discovering what variables are required for a template
- Getting template metadata before rendering
- Checking template modification dates
- Getting links to related endpoints
Usage Limits
- This endpoint does not consume any credits
- Rate limits may apply based on your plan