# Enviar mensaje de WhatsApp

POST `https://api.bydomu.com/v1/conversations/{contactId}/messages`

This reference is generated from the API’s code, so descriptions are in Spanish. Names, parameters and examples are the same in every language.

Envía un mensaje al contacto respetando la ventana de servicio de 24 h de Meta.

- **Ventana abierta:** manda `body` y se entrega como texto libre (la respuesta es el mensaje guardado).
- **Ventana cerrada:** manda `templateId` + `variables` con una plantilla APROBADA (la respuesta trae `waMessageId`, `renderedBody` y `usage`).
- **Ninguna de las dos es posible** (opt-out, sin plantilla, sin ventana): `409 CONFLICT` con el motivo en `error.message`, el modo en `error.reason` (`FREE_FORM`, `TEMPLATE_ONLY`, `HUMAN_AGENT_ONLY`, `BLOCKED`) y, si falta la plantilla, `error.windowExpiresAt`.

La API nunca envía como `human_agent`: esa vía es de una persona real en el buzón. Si la organización no tiene un número de WhatsApp activo, responde `404`.

Permission required

`messages:write`

Required header

`X-API-Key` · secret key

Access level

Level 3 · with support review

## Path parameters

1 · required

`contactId` string · **required**

ID del contacto

## Headers

1 · all optional

`Idempotency-Key` string · optional

Clave única de la operación (8-128 caracteres de `[a-zA-Z0-9._:-]`). Un reintento con la misma clave y el mismo cuerpo devuelve la respuesta original sin repetir la operación. Vive 24 horas. 8–128 chars

## Body (JSON)

3 · all optional

`body` string · optional

Texto libre. Solo con la ventana de 24 h abierta. 1–4096 chars

`templateId` string · optional

Plantilla aprobada, para la ventana cerrada.

`variables` object · optional

Valores de las variables de la plantilla. default {}

## Response 201

`SentMessage` · 10 fields

**`data` Ventana abierta: el mensaje guardado.**

`id` string

`waMessageId` string

`channel` string WHATSAPP, INSTAGRAM, FACEBOOK, SMS, EMAIL, WEB

`direction` string INBOUND, OUTBOUND

`type` string TEXT, IMAGE, DOCUMENT, AUDIO, VIDEO, LOCATION

`body` string

`timestamp` string

`contactId` string

`agentId` string

**`agent` id · firstName · lastName**

`id` string

`firstName` string

`lastName` string

## Possible errors

shaped as `{ "error": { "code", "message" } }`

- **400** Datos inválidos: el cuerpo o la query no cumplen el esquema, o `Idempotency-Key` está mal formada.
- **401** UNAUTHORIZED
- **402** PAYMENT_REQUIRED
- **403** FORBIDDEN
- **404** NOT_FOUND
- **409** DUPLICATE
- **429** RATE_LIMITED
- **500** INTERNAL_ERROR
- **502** WHATSAPP_ERROR

cURL:

```bash
curl -X POST "https://api.bydomu.com/v1/conversations/clx1con001/messages" \
  -H "X-API-Key: $BYDOMU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "body": "Hola María, ¿te queda bien la visita del jueves a las 10?"
}'
```

JavaScript:

```js
import { ByDomu } from "@bydomu/sdk";

const bydomu = new ByDomu({
  apiKey: process.env.BYDOMU_API_KEY,
});

const { data } = await bydomu.conversations.sendMessage("clx1con001", {
  "body": "Hola María, ¿te queda bien la visita del jueves a las 10?"
});
```

Python:

```python
import os, requests

r = requests.post(
    "https://api.bydomu.com/v1/conversations/clx1con001/messages",
    headers={"X-API-Key": os.environ["BYDOMU_API_KEY"]},
    json={
        "body": "Hola María, ¿te queda bien la visita del jueves a las 10?"
    }
)
data = r.json()
```

**Response · 201 · example**

```json
{
  "data": {
    "id": "clx1msg002",
    "waMessageId": "wamid.HBgMNTczMDAxMjM0NTY3FQIAERgSQzU",
    "channel": "WHATSAPP",
    "direction": "INBOUND",
    "type": "TEXT",
    "body": "Hola María, ¿te queda bien la visita del jueves a las 10?",
    "timestamp": "2026-09-25T10:35:00.000Z",
    "contactId": "clx1con001",
    "agentId": "clx1usr001",
    "agent": {
      "id": "clx1usr001",
      "firstName": "Carlos",
      "lastName": "Rodríguez"
    }
  }
}
```
