Ejemplos de código
# Enviar mensaje de texto
curl -X POST https://tu-dominio.com/v1/messages/text \
-H "Authorization: Bearer wsd_..." \
-H "Content-Type: application/json" \
-d '{"to":"34612345678","body":"Hola!"}'
# Enviar OTP
curl -X POST https://tu-dominio.com/v1/otp/send \
-H "Authorization: Bearer wsd_..." \
-H "Content-Type: application/json" \
-d '{"to":"34612345678","template":"Tu código: {{otp}}"}'
# Verificar OTP
curl -X POST https://tu-dominio.com/v1/otp/verify \
-H "Authorization: Bearer wsd_..." \
-H "Content-Type: application/json" \
-d '{"to":"34612345678","code":"483921"}'
// npm install node-fetch (Node 17 en adelante: fetch nativo)
const BASE = 'https://tu-dominio.com/v1';
const TOKEN = 'wsd_...';
async function sendMessage(to, body) {
const res = await fetch(`${BASE}/messages/text`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ to, body }),
});
return res.json();
}
async function sendOtp(to) {
const res = await fetch(`${BASE}/otp/send`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ to, template: 'Tu código: {{otp}}' }),
});
return res.json();
}
async function verifyOtp(to, code) {
const res = await fetch(`${BASE}/otp/verify`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ to, code }),
});
return res.json(); // { success: true, data: { valid: true } }
}
<?php
define('BASE', 'https://tu-dominio.com/v1');
define('TOKEN', 'wsd_...');
function waRequest($endpoint, $payload) {
$ch = curl_init(BASE . $endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . TOKEN,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$res = json_decode(curl_exec($ch), true);
curl_close($ch);
return $res;
}
// Enviar mensaje
$r = waRequest('/messages/text', ['to' => '34612345678', 'body' => 'Hola!']);
// Enviar OTP
$r = waRequest('/otp/send', ['to' => '34612345678', 'template' => 'Código: {{otp}}']);
// Verificar OTP
$r = waRequest('/otp/verify', ['to' => '34612345678', 'code' => '483921']);
var_dump($r['data']['valid']); // bool(true)
# pip install requests
import requests
BASE = 'https://tu-dominio.com/v1'
HEADERS = {
'Authorization': 'Bearer wsd_...',
'Content-Type': 'application/json',
}
# Enviar mensaje de texto
r = requests.post(f'{BASE}/messages/text',
headers=HEADERS,
json={'to': '34612345678', 'body': 'Hola!'})
print(r.json())
# Enviar OTP
r = requests.post(f'{BASE}/otp/send',
headers=HEADERS,
json={'to': '34612345678', 'template': 'Código: {{otp}}'})
# Verificar OTP
r = requests.post(f'{BASE}/otp/verify',
headers=HEADERS,
json={'to': '34612345678', 'code': '483921'})
print(r.json()['data']['valid']) # True
package main
import (
"bytes"; "encoding/json"; "fmt"; "net/http"
)
const (
base = "https://tu-dominio.com/v1"
token = "wsd_..."
)
func waPost(endpoint string, payload any) (map[string]any, error) {
b, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", base+endpoint, bytes.NewBuffer(b))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { return nil, err }
defer resp.Body.Close()
var result map[string]any
json.NewDecoder(resp.Body).Decode(&result)
return result, nil
}
func main() {
// Enviar mensaje
r, _ := waPost("/messages/text",
map[string]any{"to": "34612345678", "body": "Hola!"})
fmt.Println(r)
// Verificar OTP
r, _ = waPost("/otp/verify",
map[string]any{"to": "34612345678", "code": "483921"})
fmt.Println(r["data"])
}