MailBuildrMailBuildr.com

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.

🔑 Plan BUSINESS requis pour l'accès API

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.

bash
curl https://mailbuildr.com/api/compile-blocks \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"blocks": [...]}'
CodeSignification
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

LimiteFREEPROBUSINESS
Appels POST /api/compile-blocksIllimité
Appels POST /api/blocks/create500 / mois
Appels POST /api/blocks/modify500 / mois
Templates GET/POSTIllimité

Endpoints

POST/api/compile-blocks

Compile 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

json
{
  "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

json
{
  "html": "<!DOCTYPE html><html>... votre email compilé ...</html>",
  "size": 12480
}
POST/api/blocks/create

Gé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

json
{
  "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

json
{
  "blocks": [...],      // Arbre JSON DSL complet
  "creditsUsed": 1,
  "creditsRemaining": 499
}
POST/api/blocks/modify

Modifie 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

json
{
  "blocks": [...],   // Arbre existant
  "instruction": "Change la couleur du bouton CTA en vert et rends le texte plus court, max 3 mots."
}

Réponse

json
{
  "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

json
{
  "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

PropriétéTypeDescription
backgroundColorstringCouleur de fond en hex (#ffffff) ou "transparent"
colorstringCouleur du texte en hex
fontSizenumberTaille de police en px
fontFamilystring"Arial" | "Georgia" | "Courier New" | …
fontWeightstring"normal" | "bold"
textAlignstring"left" | "center" | "right"
paddingTop / Right / Bottom / LeftnumberEspacement intérieur en px
borderWidthnumberÉpaisseur de bordure en px
borderColorstringCouleur de bordure en hex
borderStylestring"solid" | "dashed" | "dotted"
borderRadiusnumberArrondi des coins en px
widthnumber | 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 images
hrefstringURL de destination du clic (optionnel)
type: "button"
textstringTexte affiché sur le bouton
hrefstringURL de destination du clic
type: "divider"
thicknessnumberÉpaisseur en px (défaut : 1)
type: "spacer"
heightnumberHauteur en px (défaut : 20)
type: "video"
videoUrlstringURL YouTube ou Vimeo
thumbnailUrlstringURL de la vignette (générée automatiquement si absent)
type: "blockquote"
textstringTexte de la citation
attributionstringAuteur / 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 à rebours

Exemples complets

curl — Générer un email

bash
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

javascript
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

python
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)}')