Skip to main content

Endpoints

MéthodeEndpoint
GET/api/v1/templates
POST/api/v1/templates
GET/api/v1/templates/{id}
PUT/api/v1/templates/{id}
DELETE/api/v1/templates/{id}
POST/api/v1/templates/{id}/preview
Authentification : x-api-key: <api_key>

Modèles de paramètres

GET /api/v1/templates

ParamètreTypeRequisEmplacementDescription
pageintegernonqueryPage, défaut 1
limitintegernonqueryTaille, défaut 20, max 100

POST /api/v1/templates

ChampTypeRequisEmplacementDescription
namestringouibodyNom du template
typeenumouibodytext, image, video, audio, document
bodystringoui si type=textbodyCorps avec placeholders
mediaUrlstringoui si template mediabodyURL publique du media

POST /api/v1/templates/{id}/preview

ChampTypeRequisEmplacementDescription
idUUIDouipathID du template
instanceIdUUIDnonbodyContexte instance.*
contactIdUUIDnonbodyContexte contact.*
variablesobjectnonbodyValeurs custom.*

Syntaxe des variables

Format :
{{namespace.variable}}
Namespaces supportés :
  • contact.*
  • user.*
  • instance.*
  • custom.*
Exemple :
Bonjour {{contact.firstName}}, votre code {{custom.code}} est prêt sur {{instance.name}}.
Les variables sont détectées et recalculées automatiquement par le backend à partir du body. Vous n’avez pas à maintenir manuellement la liste variables.

Créer un template

curl -X POST https://srv.msgflash.com/api/v1/templates \
  -H "x-api-key: msgf_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Relance panier",
    "type": "text",
    "body": "Bonjour {{contact.firstName}}, utilisez {{custom.code}} aujourd''hui."
  }'
Réponse :
{
  "data": {
    "id": "tmpl_uuid",
    "name": "Relance panier",
    "type": "text",
    "body": "Bonjour {{contact.firstName}}, utilisez {{custom.code}} aujourd'hui.",
    "mediaUrl": null,
    "variables": ["contact.firstName", "custom.code"]
  }
}

Erreurs courantes

CodeHTTPQuand
VALIDATION_ERROR400Body invalide
TEMPLATE_INVALID400Placeholder invalide

Preview

curl -X POST https://srv.msgflash.com/api/v1/templates/TEMPLATE_ID/preview \
  -H "x-api-key: msgf_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "instanceId": "INSTANCE_UUID",
    "contactId": "CONTACT_UUID",
    "variables": {
      "code": "PROMO10"
    }
  }'
{
  "data": {
    "rendered": "Bonjour Awa, utilisez PROMO10 aujourd'hui.",
    "variables": ["contact.firstName", "custom.code"],
    "missingVariables": [],
    "valid": true
  }
}
Si une variable ne peut pas être résolue :
  • valid devient false
  • missingVariables liste les chemins manquants

Erreurs courantes

CodeHTTPQuand
NOT_FOUND404Template introuvable
TEMPLATE_CONTEXT_UNAVAILABLE400Contact ou instance de contexte manquant

Templates media

Pour image, video, audio ou document, le backend exige mediaUrl. Exemple :
{
  "name": "Brochure",
  "type": "document",
  "body": "Voici votre brochure {{contact.firstName}}.",
  "mediaUrl": "https://cdn.example.com/brochure.pdf"
}