Publicar no canal
/v1/instances/{id}/channels/{jid}/messagesdesde M10token da instância ou adminQuando usar
Publica texto, imagem, vídeo, áudio ou documento num canal de que o número é dono ou admin (403 forbidden caso contrário). Vai pela fila de envio; aceita ?wait=true e client_message_id.
Autenticação
Aceita o token da instância (só a própria instância) ou o token admin. Um token de outra instância recebe 403 forbidden (ou 404 not_found em webhooks de outra instância).
Parâmetros
Caminho
| Nome | Tipo | Descrição |
|---|---|---|
idobrigatório | string | Id da instância (inst_...). |
jidobrigatório | string | JID do canal (<id>@newsletter) ou só o id numérico. |
Corpo (JSON)
| Nome | Tipo | Descrição |
|---|---|---|
typeobrigatório | "text" | "image" | "video" | "audio" | "document" | |
text | string | |
caption | string | |
media | MediaInput | Informe url ou base64. |
media.url | string | http(s) público; o servidor baixa (timeout 30s, sem IPs privados). |
media.base64 | string | |
media.mime | string | |
media.file_name | string | Até 255 bytes. |
media.ptt | boolean | Áudio como mensagem de voz. |
media.url | string | http(s) público; o servidor baixa (timeout 30s, sem IPs privados). |
media.base64 | string | |
media.mime | string | |
media.file_name | string | Até 255 bytes. |
media.ptt | boolean | Áudio como mensagem de voz. |
client_message_id | string | |
expires_after | string |
Exemplo
curl -s -X POST "$LITEZAP_URL/v1/instances/$ID/channels/$JID/messages" \ -H "Authorization: Bearer $LITEZAP_TOKEN" \ -d '{"type":"text","text":"Promoção relâmpago até 18h!"}'const res = await fetch("http://localhost:8787/v1/instances/inst_7f3a9c2e5b1d4086/channels/[email protected]/messages", { method: "POST", headers: { Authorization: `Bearer ${process.env.LITEZAP_TOKEN}`, "Content-Type": "application/json" }, body: JSON.stringify({ "type": "text", "text": "Promoção relâmpago até 18h!" }),});console.log(res.status, res.status === 204 ? "" : await res.json());import osimport requests
r = requests.post( headers={"Authorization": f"Bearer {os.environ['LITEZAP_TOKEN']}"}, json={ "type": "text", "text": "Promoção relâmpago até 18h!", }, timeout=150,)print(r.status_code, r.json() if r.content else "")package main
import ( "fmt" "io" "net/http" "os" "strings")
func main() { req, _ := http.NewRequest("POST", "http://localhost:8787/v1/instances/inst_7f3a9c2e5b1d4086/channels/[email protected]/messages", strings.NewReader(`{"type":"text","text":"Promoção relâmpago até 18h!"}`)) req.Header.Set("Authorization", "Bearer "+os.Getenv("LITEZAP_TOKEN")) req.Header.Set("Content-Type", "application/json") resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() out, _ := io.ReadAll(resp.Body) fmt.Println(resp.Status, string(out))}<?phprequire 'vendor/autoload.php'; // composer require guzzlehttp/guzzle
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost:8787']);$res = $client->request('POST', '/v1/instances/inst_7f3a9c2e5b1d4086/channels/[email protected]/messages', [ 'headers' => ['Authorization' => 'Bearer ' . getenv('LITEZAP_TOKEN')], 'json' => [ 'type' => 'text', 'text' => 'Promoção relâmpago até 18h!', ], 'http_errors' => false,]);echo $res->getStatusCode(), ' ', $res->getBody(), PHP_EOL;Nos exemplos, LITEZAP_URL é a URL base (ex.: http://localhost:8787) e o token vem deLITEZAP_TOKEN (instância) ou LITEZAP_ADMIN_TOKEN.
Resposta
200 Publicado.
Campos de Message
id | string | |
client_message_id | string | |
wa_message_id | string | |
chat | string | |
sender | string | |
from_me | boolean | |
source | "contact" | "api" | "device" | "history" | |
type | string | |
text | string | |
media | MediaInfo | |
media.id | string | Id da mídia recebida. |
media.kind | string | |
media.mime | string | |
media.size | integer | |
media.file_name | string | |
media.seconds | integer | |
media.ptt | boolean | |
media.url | string | Caminho da API para baixar (mídia recebida). |
reaction_to | string | |
status | "queued" | "in_flight" | "sent" | "delivered" | "read" | "played" | "failed" | "received" | "pending" | |
attempts | integer | |
error | string | Último erro (codigo: detalhe) de item não enviado. |
timestamp | string |
202 Na fila.
Campos de Message
id | string | |
client_message_id | string | |
wa_message_id | string | |
chat | string | |
sender | string | |
from_me | boolean | |
source | "contact" | "api" | "device" | "history" | |
type | string | |
text | string | |
media | MediaInfo | |
media.id | string | Id da mídia recebida. |
media.kind | string | |
media.mime | string | |
media.size | integer | |
media.file_name | string | |
media.seconds | integer | |
media.ptt | boolean | |
media.url | string | Caminho da API para baixar (mídia recebida). |
reaction_to | string | |
status | "queued" | "in_flight" | "sent" | "delivered" | "read" | "played" | "failed" | "received" | "pending" | |
attempts | integer | |
error | string | Último erro (codigo: detalhe) de item não enviado. |
timestamp | string |
Erros
| Código | HTTP | Retentável | O que fazer |
|---|---|---|---|
validation_failed | 400 | não | Corrija o corpo ou os parâmetros; a message diz o campo. |
unauthorized | 401 | não | Envie Authorization: Bearer <token> válido. |
forbidden | 403 | não | Use o token certo (admin, ou o da própria instância). |
not_found | 404 | não | Confira o id do recurso (mensagem, chat, contato, mídia ou webhook). |
instance_not_found | 404 | não | Confira o id da instância. |
Todo erro usa o envelope {"error":{"code","message","retryable"}}. Tabela completa em Erros.
Eventos gerados
Equivalente na Z-API: (via enviar mensagem para o canal). Veja Migrar da Z-API.
Outras operações de Canais: Listar canais seguidos · Criar canal · Canal por link de convite · Metadados do canal · Seguir, deixar de seguir, silenciar · Publicações do canal · Reagir a publicação

