Send a campaign

SDK platic.campaigns.previewSend()
SDK platic.campaigns.send()

First request a preview. It shows the recipients, sender number, message with real data, cost, and who will answer replies. It does not send messages.

Then confirm with the preview's confirmation to send exactly what you reviewed.

Before you start: prepare the audience and an approved template. Save the id in CAMPAIGN_ID. Configure the template, buttons, and link destination with update a campaign before sending.

1. See what would go out

Decide three things: who answers the replies (replyHandling), which number it goes out from (senderChannelId), and what fills the template variables (variables).

const campaignId = process.env.CAMPAIGN_ID!;
const decisions = {
  replyHandling: "agent",
  responderAgentId: process.env.AGENT_ID!,
  senderChannelId: "wb-123456789",
  variables: ["client_firstname"],
} as const;

const preview = await platic.campaigns.previewSend(campaignId, decisions);
console.log(preview.resumen, preview.avisos);

Review resumen (summary), mensaje (with real contact data), variables_sin_resolver (unresolved variables), and avisos (warnings). The campaign stays unchanged until you confirm the send.

2. Confirm the send

Send the confirmation with the same decisions as the preview. It is valid for 30 minutes and works for a single send.

if (preview.confirmation) {
  const sent = await platic.campaigns.send(campaignId, { ...decisions, confirmation: preview.confirmation });
  console.log(sent.runId);
}

The response includes a runId as soon as the send is queued. Messages are sent afterwards. Check progress in the funnel instead of requesting another send.

If the audience, template, or link destination changed after the preview, the API returns 409 without sending messages and identifies the change. Request another preview. A used confirmation also returns 409.

Preview reference

ParameterInTypeDescriptionRequired
campaignIdpathstringThe campaign id✓
workspacequerystringThe campaign's workspace, if the credential covers several—

Request body

FieldTypeDescriptionRequired
replyHandlingstringagent: an agent answers the replies. none: nobody answers them and they stay in the inbox✓
responderAgentIdstringThe agent that answers. Required with replyHandling: "agent"; it does not need to be assigned to the channel—
senderChannelIdstringThe channel that sends, with its prefix (wb-…), from the same WhatsApp account as the template. If it is not, the error says which ones work✓
variablesstring[]The value of each {{n}} in the body, in order: a contact field (client_firstname, client_name…), a custom field, or a fixed text. Empty if the template has no variables—
sendToProblematicbooleanIncludes the contacts that Meta is limiting by volume. Almost always false: those sends tend to fail. Default false—
scheduledDatesstring[]Future moments in ISO 8601 with a time zone, such as 2026-12-01T18:00:00Z. Each date is another complete send to the same audience and costs again. Empty to send now—

Blocked contacts and contacts who unsubscribed from marketing are always left out.

Response

{
  "status": "success",
  "message": "1,250 destinatarios · $1,087.50 MXN + IVA ($1,261.50 MXN con IVA) · envío inmediato",
  "data": {
    "confirmation": "eyJ2IjoxLCJmIjoi…",
    "requiere_autorizacion": false,
    "resumen": "1,250 destinatarios · $1,087.50 MXN + IVA ($1,261.50 MXN con IVA) · envío inmediato",
    "destinatarios": {
      "reciben": 1250,
      "activos": 1240,
      "con_restricciones_meta": 10,
      "excluidos": 12,
      "bloqueados": 3,
      "numero_no_entregable": 4,
      "baja_de_marketing": 5,
      "nota_bajas": "5 contactos respondieron STOP o se dieron de baja del marketing. …"
    },
    "canal": { "channelId": "wb-123456789", "numero": "+52 55 1234 5678", "nombre": "Acme Store", "wabaId": "1029384756", "tier": "TIER_10K" },
    "plantilla": { "nombre": "spring_sale", "idioma": "en_US", "categoria": "MARKETING", "estado": "APPROVED" },
    "respuestas": "Contesta el agente Sales.",
    "enlace_medido": { "destino": "https://example.com/spring", "nota": "Cada destinatario recibe su propio enlace firmado; el click y la compra se miden." },
    "mensaje": ["Hi Ana, the spring sale has started…", "Hi Luis, the spring sale has started…"],
    "variables_sin_resolver": [],
    "costo_estimado_antes_de_iva_mxn": 1087.5,
    "costo_estimado_mxn": 1261.5,
    "envios_programados": 1,
    "mensajes_en_total": 1250,
    "avisos": [],
    "siguiente_paso": "Enseña esto al usuario —a cuántos va, el mensaje, el costo— y espera su OK explícito. …"
  }
}

The response is written in Spanish for the person who approves the send; the field names below keep that language.

FieldDescription
confirmationThe only thing that authorizes the send. It is valid for 30 minutes and a single send. It does not arrive with requiere_autorizacion: true
requiere_autorizaciontrue if the send goes over 5,000 messages in 24 hours; autorizacion explains why
destinatariosHow many receive it and how many are left out, and why
canal, plantillaWhere it goes out from and which template, with its status in Meta
respuestasWho answers, in words
enlace_medidoThe button destination, if the campaign has one; null if not
mensajeThe message text with the variables resolved on some real contacts
variables_sin_resolverThe variables that ended up empty in those examples
costo_estimado_antes_de_iva_mxn, costo_estimado_mxnThe estimated cost, before and after VAT
envios_programados, mensajes_en_totalHow many complete sends and how many messages in total
avisosTexts with what is worth saying before sending

Send reference

It takes the same path and query parameters as the preview.

Request body

The confirmation and the same fields as the preview, with the same values:

FieldTypeDescriptionRequired
confirmationstringThe confirmation from the preview✓
replyHandling, responderAgentId, senderChannelId, variables, sendToProblematic, scheduledDatesAs in the preview

Response

{
  "status": "success",
  "message": "Campaign send queued",
  "data": {
    "estado": "encolado",
    "runId": "run_8fK2pQx7",
    "programado": null,
    "destinatarios": 1250,
    "canal": "wb-123456789",
    "plantilla": "spring_sale",
    "respuestas": "el agente Sales",
    "destino_medido": "https://example.com/spring",
    "siguiente_paso": "Dile al usuario que el envío arrancó y con cuántos destinatarios. …"
  }
}
FieldDescription
estadoencolado (goes out now) or programado (with scheduledDates); in the second case message is Campaign scheduled
runIdThe send run; with several dates, the first one, and runIds carries all of them
programadoThe scheduled dates, or null
destinatariosHow many each send goes to; with several dates, envios and destinatarios_totales
canal, plantilla, respuestas, destino_medidoWhat was sent

Errors

Statusdetails.codeWhen
400INVALID_REQUESTconfirmation is missing when sending, responderAgentId is missing with replyHandling: "agent", the channel is not from the template's WhatsApp account, the template is not approved, or the credential covers several workspaces and workspace is missing. The body says what to fix
403FORBIDDENThe send goes over 5,000 messages in 24 hours (details.motivo: "requiere_autorizacion", with destinatarios, mensajes, ya_en_ventana, and umbral): a person launches it from the dashboard
404NOT_FOUNDThere is no campaign with that id
409CONFLICTSomething changed since the preview or the confirmation is not usable (details.motivo: stale, expired, missing, malformed, or tampered; with stale, details.cambio says what changed: alcance, audiencia, mensaje, canal, or programacion), the confirmation was already used (details.runId), or another send of the campaign is in progress. Ask for another preview
502UPSTREAM_ERRORPlatica could not queue the send. If details.ejecuciones_creadas is 0, nothing went out and you can retry with the same confirmation. If part of it went out, details.parcial is true, details.ejecuciones_creadas lists the ones that did (runId, programada), and details.fechas_sin_encolar the ones that did not: preview again with only those dates
{
  "code": 409,
  "error": "Conflict - The resource state conflicts with this request",
  "details": {
    "code": "CONFLICT",
    "message": "Platica refused the operation",
    "error": "Algo cambió desde la vista previa: la audiencia.",
    "motivo": "stale",
    "cambio": ["audiencia"]
  }
}

See Errors for the full shape of an error.

An error response never carries a confirmation.