Documentation / API Whatixo
Exemples complets
Un petit client réutilisable dans votre langage, puis des cas d’usage concrets à adapter.
Un client en quelques lignes
// whatixo.js — Node.js 18+
const BASE = 'https://api.whatixo.com/api';
export async function whatixo(path, body = {}) {
const res = await fetch(BASE + path, {
method: 'POST',
headers: {
'x-api-key': process.env.WHATIXO_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
const err = new Error(data.error || `HTTP ${res.status}`);
err.status = res.status; err.code = data.code;
throw err;
}
return data;
}
export const DEVICE_ID = process.env.WHATIXO_DEVICE_ID;<?php
// whatixo.php — PHP 7.4+
const WHATIXO_BASE = 'https://api.whatixo.com/api';
function whatixo(string $path, array $body = []): array {
$ch = curl_init(WHATIXO_BASE . $path);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'x-api-key: ' . getenv('WHATIXO_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($body),
]);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($raw ?: '{}', true) ?: [];
if ($status >= 400) {
throw new RuntimeException($data['error'] ?? "HTTP $status", $status);
}
return $data;
}# whatixo.py — Python 3.8+ (pip install requests)
import os
import requests
BASE = "https://api.whatixo.com/api"
SESSION = requests.Session()
SESSION.headers.update({"x-api-key": os.environ["WHATIXO_API_KEY"]})
class WhatixoError(Exception):
def __init__(self, status, message, code=None):
super().__init__(message)
self.status, self.code = status, code
def whatixo(path, body=None):
res = SESSION.post(BASE + path, json=body or {}, timeout=30)
data = res.json() if res.content else {}
if not res.ok:
raise WhatixoError(res.status_code, data.get("error", res.reason), data.get("code"))
return data
DEVICE_ID = os.environ.get("WHATIXO_DEVICE_ID").envBASH
WHATIXO_API_KEY=wtx_votre_cle_secrete
WHATIXO_DEVICE_ID=8f2c1a7e-4b9d-4e21-9a6f-3c5d7e1b2a90
Confirmation de commande avec facture
import { whatixo, DEVICE_ID } from './whatixo.js';
export async function notifyOrder(order) {
// 1. Enregistrer / mettre à jour le client dans le CRM (le tag peut lancer une séquence)
await whatixo('/whatsapp/contacts/upsert', {
phone: order.customer.phone,
name: order.customer.name,
tags: ['clients'],
attributes: { derniere_commande: String(order.id) },
});
// 2. Message de confirmation
await whatixo('/whatsapp/messages/send', {
deviceId: DEVICE_ID,
to: order.customer.phone,
text: `Bonjour ${order.customer.name} 👋\nVotre commande *n°${order.id}* de ${order.total} $ est confirmée.`,
});
// 3. La facture en PDF
await whatixo('/whatsapp/messages/send', {
deviceId: DEVICE_ID,
to: order.customer.phone,
type: 'document',
mediaUrl: order.invoiceUrl, // https://…/facture-1042.pdf
fileName: `Facture-${order.id}.pdf`,
});
}require 'whatixo.php';
function notifyOrder(array $order): void {
$device = getenv('WHATIXO_DEVICE_ID');
whatixo('/whatsapp/contacts/upsert', [
'phone' => $order['phone'], 'name' => $order['name'], 'tags' => ['clients'],
]);
whatixo('/whatsapp/messages/send', [
'deviceId' => $device,
'to' => $order['phone'],
'text' => "Bonjour {$order['name']} 👋\nVotre commande *n°{$order['id']}* est confirmée.",
]);
whatixo('/whatsapp/messages/send', [
'deviceId' => $device,
'to' => $order['phone'],
'type' => 'document',
'mediaUrl' => $order['invoice_url'],
'fileName' => "Facture-{$order['id']}.pdf",
]);
}from whatixo import whatixo, DEVICE_ID
def notify_order(order):
whatixo("/whatsapp/contacts/upsert", {
"phone": order["phone"], "name": order["name"], "tags": ["clients"],
})
whatixo("/whatsapp/messages/send", {
"deviceId": DEVICE_ID,
"to": order["phone"],
"text": f"Bonjour {order['name']} 👋\nVotre commande *n°{order['id']}* est confirmée.",
})
whatixo("/whatsapp/messages/send", {
"deviceId": DEVICE_ID,
"to": order["phone"],
"type": "document",
"mediaUrl": order["invoice_url"],
"fileName": f"Facture-{order['id']}.pdf",
})Code de vérification (OTP) par WhatsApp
Remplacez le SMS par WhatsApp pour vérifier le numéro de vos utilisateurs.
otp.jsJS
import crypto from 'node:crypto';
import { whatixo, DEVICE_ID } from './whatixo.js';
const pending = new Map(); // en production : Redis ou base de données
export async function sendOtp(phone) {
const code = String(crypto.randomInt(100000, 1000000));
const hash = crypto.createHash('sha256').update(code).digest('hex');
pending.set(phone, { hash, expires: Date.now() + 10 * 60_000, tries: 0 });
await whatixo('/whatsapp/messages/send', {
deviceId: DEVICE_ID,
to: phone,
text: `Votre code de vérification : *${code}*\nIl expire dans 10 minutes. Ne le partagez avec personne.`,
});
}
export function verifyOtp(phone, code) {
const entry = pending.get(phone);
if (!entry || entry.expires < Date.now() || ++entry.tries > 5) return false;
const ok = crypto.createHash('sha256').update(String(code)).digest('hex') === entry.hash;
if (ok) pending.delete(phone);
return ok;
}
Rappels de rendez-vous (tâche planifiée)
rappels.py — à lancer chaque matin (cron)PYTHON
from datetime import date, timedelta
import time
from whatixo import whatixo, DEVICE_ID, WhatixoError
demain = date.today() + timedelta(days=1)
rdvs = charger_rendez_vous(demain) # votre fonction : [{"nom", "telephone", "heure"}]
for rdv in rdvs:
try:
whatixo("/whatsapp/messages/send", {
"deviceId": DEVICE_ID,
"to": rdv["telephone"],
"text": f"Bonjour {rdv['nom']}, rappel de votre rendez-vous demain à {rdv['heure']} ⏰\n"
"Répondez 1 pour confirmer, 2 pour annuler.",
})
except WhatixoError as e:
print("Échec", rdv["telephone"], e.status, e)
time.sleep(5) # rythme raisonnable entre deux envois
Pour gérer les réponses « 1 » et « 2 » sans code, créez deux workflows à mot-clé (1 et 2, règle est exactement) qui répondent et taguent le contact.
Une question ? Écrivez-nous depuis l’application (Aide & support) ou à support@whatixo.com.Mis à jour : novembre 2026