wsperu.devDocs

Mensajes

Enviar texto, archivos y envíos masivos; consultar estado e historial.

Todos los envíos se encolan y se despachan con delays aleatorios (anti-bloqueo). La respuesta inmediata incluye el messageId para seguimiento.

Enviar texto

POST/messages/send/text
curl -X POST "https://api.wsperu.dev/messages/send/text" \
  -H "x-api-key: TU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "sessionId": "665f...",
  "to": "51912345678",
  "text": "Su pedido está listo 🎉"
}'
<?php
$ch = curl_init("https://api.wsperu.dev/messages/send/text");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ["x-api-key: TU_API_KEY", "Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode([
        'sessionId' => '665f...',
        'to' => '51912345678',
        'text' => 'Su pedido está listo 🎉',
    ]),
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;
using System.Net.Http.Json;

var http = new HttpClient();
http.DefaultRequestHeaders.Add("x-api-key", "TU_API_KEY");

var payload = new {
    sessionId = "665f...",
    to = "51912345678",
    text = "Su pedido está listo 🎉"
};

var resp = await http.PostAsJsonAsync("https://api.wsperu.dev/messages/send/text", payload);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const resp = await fetch("https://api.wsperu.dev/messages/send/text", {
  method: "POST",
  headers: {
    "x-api-key": "TU_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    sessionId: "665f...",
    to: "51912345678",
    text: "Su pedido está listo 🎉",
  }),
});
console.log(await resp.json());
Respuesta
{
  "messageId": "665f...",
  "status": "queued",
  "jobId": "1234"
}
  • sessionId es opcional: si lo omites, se usa automáticamente tu primera línea conectada.
  • to acepta un número (con código de país, sin +) o un JID de grupo (...@g.us).

Enviar archivo

multipart/form-data. Se acepta cualquier tipo de archivo; según su extensión se envía como imagen, video, audio o documento.

POST/messages/send/file
curl -X POST "https://api.wsperu.dev/messages/send/file" \
  -H "x-api-key: TU_API_KEY" \
  -F "sessionId=665f..." \
  -F "to=51912345678" \
  -F "caption=Adjunto tu comprobante" \
  -F "file=@/ruta/factura.pdf"
<?php
$ch = curl_init("https://api.wsperu.dev/messages/send/file");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ["x-api-key: TU_API_KEY"],
    CURLOPT_POSTFIELDS => [
        'sessionId' => '665f...',
        'to' => '51912345678',
        'caption' => 'Adjunto tu comprobante',
        'file' => new CURLFile('/ruta/factura.pdf'),
    ],
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;
using System.IO;

var http = new HttpClient();
http.DefaultRequestHeaders.Add("x-api-key", "TU_API_KEY");

using var form = new MultipartFormDataContent();
form.Add(new StringContent("665f..."), "sessionId");
form.Add(new StringContent("51912345678"), "to");
form.Add(new StringContent("Adjunto tu comprobante"), "caption");
form.Add(new ByteArrayContent(File.ReadAllBytes("factura.pdf")), "file", "factura.pdf");

var resp = await http.PostAsync("https://api.wsperu.dev/messages/send/file", form);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const form = new FormData();
form.append("sessionId", "665f...");
form.append("to", "51912345678");
form.append("caption", "Adjunto tu comprobante");
form.append("file", new Blob([buffer]), "factura.pdf"); // buffer = contenido del archivo

const resp = await fetch("https://api.wsperu.dev/messages/send/file", {
  method: "POST",
  headers: { "x-api-key": "TU_API_KEY" },
  body: form,
});
console.log(await resp.json());
Respuesta
{
  "messageId": "665f...",
  "status": "queued",
  "jobId": "1234"
}
Campo Tipo Descripción
sessionId text Línea emisora (opcional)
to text Destinatario
caption text Texto que acompaña al archivo (opcional) — enviar antes del campo file
file file El archivo a enviar (cualquier tipo, ver abajo)

Según su extensión se envía como imagen, video, audio o documento:

Llega como Extensiones
Imagen png jpg jpeg gif webp
Video mp4 3gp mov
Audio mp3 ogg
Documento pdf doc docx xls xlsx ppt pptx odt ods odp rtf txt csv xml json html zip rar 7z

Cualquier otra extensión también se envía: llega como documento (archivo descargable con su nombre original). El caption acompaña a imágenes, videos y documentos.

¿Necesitás enviar un PDF en base64 (por ejemplo desde Facturador PRO 8)? Usá el endpoint dedicado Comprobantes PDF.

Enviar archivo en base64

Igual que /send/file pero recibís el archivo como base64 en JSON — útil cuando tu sistema genera el archivo en memoria (comprobantes, reportes). Acepta cualquier tipo y el tipo se detecta por la extensión del filename.

POST/messages/send/document
curl -X POST "https://api.wsperu.dev/messages/send/document" \
  -H "x-api-key: TU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "sessionId": "665f...",
  "to": "51912345678",
  "file": "UEsDBBQABgAIAAAAIQ...",
  "filename": "cotizacion.xlsx",
  "caption": "Adjunto tu cotización"
}'
<?php
$ch = curl_init("https://api.wsperu.dev/messages/send/document");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ["x-api-key: TU_API_KEY", "Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode([
        'sessionId' => '665f...',
        'to' => '51912345678',
        'file' => 'UEsDBBQABgAIAAAAIQ...',
        'filename' => 'cotizacion.xlsx',
        'caption' => 'Adjunto tu cotización',
    ]),
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;
using System.Net.Http.Json;

var http = new HttpClient();
http.DefaultRequestHeaders.Add("x-api-key", "TU_API_KEY");

var payload = new {
    sessionId = "665f...",
    to = "51912345678",
    file = "UEsDBBQABgAIAAAAIQ...",
    filename = "cotizacion.xlsx",
    caption = "Adjunto tu cotización"
};

var resp = await http.PostAsJsonAsync("https://api.wsperu.dev/messages/send/document", payload);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const resp = await fetch("https://api.wsperu.dev/messages/send/document", {
  method: "POST",
  headers: {
    "x-api-key": "TU_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    sessionId: "665f...",
    to: "51912345678",
    file: "UEsDBBQABgAIAAAAIQ...",
    filename: "cotizacion.xlsx",
    caption: "Adjunto tu cotización",
  }),
});
console.log(await resp.json());
Respuesta
{
  "messageId": "665f...",
  "status": "queued",
  "jobId": "1234"
}
  • sessionId es opcional: si lo omites, se usa tu primera línea conectada.
  • file: contenido en base64 (acepta el prefijo data:<mime>;base64,).
  • filename: nombre con extensión — de ahí se detecta el tipo (imagen, video, audio o documento; ver tabla de arriba).
  • caption es opcional. Admite archivos de hasta ~35 MB.

Envío masivo

POST/messages/send/bulk
curl -X POST "https://api.wsperu.dev/messages/send/bulk" \
  -H "x-api-key: TU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "sessionId": "665f...",
  "messages": [
    {
      "to": "51911111111",
      "text": "Hola Ana"
    },
    {
      "to": "51922222222",
      "text": "Hola Luis"
    },
    {
      "to": "51933333333",
      "fileUrl": "https://tu-cdn.com/promo.jpg",
      "caption": "Nueva promo"
    }
  ]
}'
<?php
$ch = curl_init("https://api.wsperu.dev/messages/send/bulk");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ["x-api-key: TU_API_KEY", "Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode([
        'sessionId' => '665f...',
        'messages' => [
            [
                'to' => '51911111111',
                'text' => 'Hola Ana',
            ],
            [
                'to' => '51922222222',
                'text' => 'Hola Luis',
            ],
            [
                'to' => '51933333333',
                'fileUrl' => 'https://tu-cdn.com/promo.jpg',
                'caption' => 'Nueva promo',
            ],
        ],
    ]),
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;
using System.Net.Http.Json;

var http = new HttpClient();
http.DefaultRequestHeaders.Add("x-api-key", "TU_API_KEY");

var payload = new {
    sessionId = "665f...",
    messages = new object[] {
        new {
            to = "51911111111",
            text = "Hola Ana"
        },
        new {
            to = "51922222222",
            text = "Hola Luis"
        },
        new {
            to = "51933333333",
            fileUrl = "https://tu-cdn.com/promo.jpg",
            caption = "Nueva promo"
        }
    }
};

var resp = await http.PostAsJsonAsync("https://api.wsperu.dev/messages/send/bulk", payload);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const resp = await fetch("https://api.wsperu.dev/messages/send/bulk", {
  method: "POST",
  headers: {
    "x-api-key": "TU_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    sessionId: "665f...",
    messages: [
      {
        to: "51911111111",
        text: "Hola Ana",
      },
      {
        to: "51922222222",
        text: "Hola Luis",
      },
      {
        to: "51933333333",
        fileUrl: "https://tu-cdn.com/promo.jpg",
        caption: "Nueva promo",
      },
    ],
  }),
});
console.log(await resp.json());

Los mensajes se espacian automáticamente según los delays de tu plan. El total no puede exceder tu cuota mensual disponible.

Estado de un mensaje

GET/messages/{id}/status
curl "https://api.wsperu.dev/messages/{id}/status" \
  -H "x-api-key: TU_API_KEY"
<?php
$ch = curl_init("https://api.wsperu.dev/messages/{id}/status");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ["x-api-key: TU_API_KEY"],
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;

var http = new HttpClient();
http.DefaultRequestHeaders.Add("x-api-key", "TU_API_KEY");

var resp = await http.GetAsync("https://api.wsperu.dev/messages/{id}/status");
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const resp = await fetch("https://api.wsperu.dev/messages/{id}/status", {
  headers: { "x-api-key": "TU_API_KEY" },
});
console.log(await resp.json());
Respuesta
{
  "messageId": "665f...",
  "status": "sent",
  "sentAt": "2026-08-12T15:05:11.000Z"
}

status: queued → processing → sent | failed. Además del estado de envío, el estado de entrega (delivered/read) llega por webhook message.status.

Historial

GET/messages/history?page=1&limit=20&status=sent&from=2026-08-01&to=2026-08-12
curl "https://api.wsperu.dev/messages/history?page=1&limit=20&status=sent&from=2026-08-01&to=2026-08-12" \
  -H "x-api-key: TU_API_KEY"
<?php
$ch = curl_init("https://api.wsperu.dev/messages/history?page=1&limit=20&status=sent&from=2026-08-01&to=2026-08-12");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ["x-api-key: TU_API_KEY"],
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
using System;
using System.Net.Http;

var http = new HttpClient();
http.DefaultRequestHeaders.Add("x-api-key", "TU_API_KEY");

var resp = await http.GetAsync("https://api.wsperu.dev/messages/history?page=1&limit=20&status=sent&from=2026-08-01&to=2026-08-12");
Console.WriteLine(await resp.Content.ReadAsStringAsync());
const resp = await fetch("https://api.wsperu.dev/messages/history?page=1&limit=20&status=sent&from=2026-08-01&to=2026-08-12", {
  headers: { "x-api-key": "TU_API_KEY" },
});
console.log(await resp.json());

Todos los filtros son opcionales. Respuesta paginada con pagination: { page, limit, total }.