API
Référence API
Intégrez MailBuildr dans vos outils internes, workflows d'automatisation ou plateformes SaaS. L'API REST permet de générer, compiler et modifier des emails par programme.
Authentification
Toutes les requêtes API nécessitent un header x-api-key contenant votre clé API BUSINESS. Récupérez votre clé depuis /builder/billing.
curl https://mailbuildr.com/api/compile-blocks \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"blocks": [...]}'200 OKRequête traitée avec succès.400 Bad RequestCorps de requête invalide ou paramètre manquant.401 UnauthorizedClé API absente ou invalide.403 ForbiddenPlan insuffisant (API nécessite BUSINESS).429 Too Many RequestsQuota mensuel atteint.500 Internal ErrorErreur serveur. Réessayez ou contactez le support.Limites d'utilisation
Appels POST /api/compile-blocks——IllimitéAppels POST /api/blocks/create——500 / moisAppels POST /api/blocks/modify——500 / moisTemplates GET/POST——IllimitéEndpoints
/api/compile-blocksCompile un arbre de blocs JSON en HTML email-safe. C'est le cœur du moteur MailBuildr — aucune IA, transformation pure du DSL vers HTML.
Corps de la requête
{
"blocks": [
{
"id": "block_001",
"type": "container",
"style": {
"backgroundColor": "#ffffff",
"paddingTop": 24,
"paddingBottom": 24,
"paddingLeft": 32,
"paddingRight": 32
},
"children": [
{
"id": "block_002",
"type": "text",
"content": "<h1>Bonjour !</h1><p>Voici votre email.</p>",
"style": { "fontSize": 16, "color": "#1d1d1f" }
},
{
"id": "block_003",
"type": "button",
"text": "Découvrir",
"href": "https://example.com",
"style": {
"backgroundColor": "#4b41e1",
"color": "#ffffff",
"borderRadius": 8
}
}
]
}
]
}Réponse
{
"html": "<!DOCTYPE html><html>... votre email compilé ...</html>",
"size": 12480
}/api/blocks/createGénère un arbre de blocs complet à partir d'une description en langage naturel (IA). Utilise GPT-4. Consomme 1 crédit IA.
Corps de la requête
{
"prompt": "Email de bienvenue pour une SaaS B2B. Header avec logo centré,
titre 'Bienvenue sur Acme', sous-titre, bouton CTA orange 'Commencer',
footer avec liens légaux."
}Réponse
{
"blocks": [...], // Arbre JSON DSL complet
"creditsUsed": 1,
"creditsRemaining": 499
}/api/blocks/modifyModifie un arbre de blocs existant selon une instruction en langage naturel. Retourne l'arbre modifié. Consomme 1 crédit IA.
Corps de la requête
{
"blocks": [...], // Arbre existant
"instruction": "Change la couleur du bouton CTA en vert et rends le texte plus court, max 3 mots."
}Réponse
{
"blocks": [...], // Arbre modifié
"creditsUsed": 1,
"creditsRemaining": 498
}DSL JSON — Structure des blocs
Un bloc est un objet JSON avec au minimum un type. Tous les champs sont optionnels sauf indication.
Structure commune
{
"id": "string", // UUID généré si absent
"type": "container | text | image | button | divider | spacer | social | video | blockquote | rawhtml | timer",
"style": { ... }, // Objet de style (voir ci-dessous)
"children": [ ... ] // Blocs enfants (container uniquement)
}Propriétés de style disponibles
backgroundColorstringCouleur de fond en hex (#ffffff) ou "transparent"colorstringCouleur du texte en hexfontSizenumberTaille de police en pxfontFamilystring"Arial" | "Georgia" | "Courier New" | …fontWeightstring"normal" | "bold"textAlignstring"left" | "center" | "right"paddingTop / Right / Bottom / LeftnumberEspacement intérieur en pxborderWidthnumberÉpaisseur de bordure en pxborderColorstringCouleur de bordure en hexborderStylestring"solid" | "dashed" | "dotted"borderRadiusnumberArrondi des coins en pxwidthnumber | stringLargeur en px ou "100%"Propriétés spécifiques par type
type: "text"contentstringHTML arbitraire (balises autorisées : h1-h6, p, strong, em, a, br, ul, li)type: "image"srcstringURL de l'image (HTTPS recommandé)altstringTexte alternatif pour les clients qui bloquent les imageshrefstringURL de destination du clic (optionnel)type: "button"textstringTexte affiché sur le boutonhrefstringURL de destination du clictype: "divider"thicknessnumberÉpaisseur en px (défaut : 1)type: "spacer"heightnumberHauteur en px (défaut : 20)type: "video"videoUrlstringURL YouTube ou VimeothumbnailUrlstringURL de la vignette (générée automatiquement si absent)type: "blockquote"textstringTexte de la citationattributionstringAuteur / source (optionnel)type: "rawhtml"htmlstringHTML brut injecté tel quel dans le rendu compilétype: "timer"targetDatestringISO 8601 (ex: "2025-12-31T23:59:59Z")labelstringTitre au-dessus du compte à reboursExemples complets
curl — Générer un email
curl -X POST https://mailbuildr.com/api/blocks/create \
-H "x-api-key: sk_live_xxxx" \
-H "Content-Type: application/json" \
-d '{"prompt": "Email de confirmation de commande avec numéro, récapitulatif produit, et CTA de suivi."}'Node.js — Pipeline complet
const API_KEY = process.env.MAILBUILDR_API_KEY;
const BASE = 'https://mailbuildr.com';
async function generateAndCompile(prompt) {
// 1. Génère l'arbre de blocs avec l'IA
const genRes = await fetch(`${BASE}/api/blocks/create`, {
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt }),
});
if (!genRes.ok) {
const err = await genRes.json();
throw new Error(`Génération échouée: ${err.error}`);
}
const { blocks } = await genRes.json();
// 2. Compile l'arbre en HTML email-safe
const compileRes = await fetch(`${BASE}/api/compile-blocks`, {
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({ blocks }),
});
const { html } = await compileRes.json();
return html;
}
// Utilisation
const html = await generateAndCompile(
'Email newsletter hebdo pour une startup FinTech, section actualités et CTA.'
);
console.log(`HTML généré: ${html.length} caractères`);Python — Modifier un email existant
import os, requests
API_KEY = os.environ['MAILBUILDR_API_KEY']
BASE = 'https://mailbuildr.com'
HEADERS = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}
def modify_blocks(blocks, instruction):
r = requests.post(
f'{BASE}/api/blocks/modify',
headers=HEADERS,
json={'blocks': blocks, 'instruction': instruction}
)
r.raise_for_status()
return r.json()['blocks']
# Charger des blocs existants (ex: depuis votre BDD)
with open('email_template.json') as f:
blocks = json.load(f)
# Modifier le CTA
updated = modify_blocks(blocks, 'Change le bouton en vert et le texte en "Voir l\'offre"')
print(f'Blocs modifiés: {len(updated)}')