Conectar canal Meta WhatsApp
curl --request POST \
--url https://api.omni.z-api.io/v1/channels/{channelId}/connect \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"wabaId": "428083093730937",
"phoneId": "123456789012345",
"code": "ABC123DEF456",
"coexistence": false
}
'import requests
url = "https://api.omni.z-api.io/v1/channels/{channelId}/connect"
payload = {
"wabaId": "428083093730937",
"phoneId": "123456789012345",
"code": "ABC123DEF456",
"coexistence": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
wabaId: '428083093730937',
phoneId: '123456789012345',
code: 'ABC123DEF456',
coexistence: false
})
};
fetch('https://api.omni.z-api.io/v1/channels/{channelId}/connect', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.omni.z-api.io/v1/channels/{channelId}/connect",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'wabaId' => '428083093730937',
'phoneId' => '123456789012345',
'code' => 'ABC123DEF456',
'coexistence' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.omni.z-api.io/v1/channels/{channelId}/connect"
payload := strings.NewReader("{\n \"wabaId\": \"428083093730937\",\n \"phoneId\": \"123456789012345\",\n \"code\": \"ABC123DEF456\",\n \"coexistence\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.omni.z-api.io/v1/channels/{channelId}/connect")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"wabaId\": \"428083093730937\",\n \"phoneId\": \"123456789012345\",\n \"code\": \"ABC123DEF456\",\n \"coexistence\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.omni.z-api.io/v1/channels/{channelId}/connect")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"wabaId\": \"428083093730937\",\n \"phoneId\": \"123456789012345\",\n \"code\": \"ABC123DEF456\",\n \"coexistence\": false\n}"
response = http.request(request)
puts response.read_body{
"success": true
}{
"error": 401,
"message": "Unauthorized"
}Canales
Conectar canal Meta WhatsApp
Flujo completo para conectar un canal META_WHATSAPP a la API Oficial de WhatsApp
POST
/
v1
/
channels
/
{channelId}
/
connect
Conectar canal Meta WhatsApp
curl --request POST \
--url https://api.omni.z-api.io/v1/channels/{channelId}/connect \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"wabaId": "428083093730937",
"phoneId": "123456789012345",
"code": "ABC123DEF456",
"coexistence": false
}
'import requests
url = "https://api.omni.z-api.io/v1/channels/{channelId}/connect"
payload = {
"wabaId": "428083093730937",
"phoneId": "123456789012345",
"code": "ABC123DEF456",
"coexistence": False
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
wabaId: '428083093730937',
phoneId: '123456789012345',
code: 'ABC123DEF456',
coexistence: false
})
};
fetch('https://api.omni.z-api.io/v1/channels/{channelId}/connect', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.omni.z-api.io/v1/channels/{channelId}/connect",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'wabaId' => '428083093730937',
'phoneId' => '123456789012345',
'code' => 'ABC123DEF456',
'coexistence' => false
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.omni.z-api.io/v1/channels/{channelId}/connect"
payload := strings.NewReader("{\n \"wabaId\": \"428083093730937\",\n \"phoneId\": \"123456789012345\",\n \"code\": \"ABC123DEF456\",\n \"coexistence\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.omni.z-api.io/v1/channels/{channelId}/connect")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"wabaId\": \"428083093730937\",\n \"phoneId\": \"123456789012345\",\n \"code\": \"ABC123DEF456\",\n \"coexistence\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.omni.z-api.io/v1/channels/{channelId}/connect")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"wabaId\": \"428083093730937\",\n \"phoneId\": \"123456789012345\",\n \"code\": \"ABC123DEF456\",\n \"coexistence\": false\n}"
response = http.request(request)
puts response.read_body{
"success": true
}{
"error": 401,
"message": "Unauthorized"
}Visión general
Después de crear un canal del tipoMETA_WHATSAPP, tienes que conectarlo a un número de WhatsApp Business. Hay dos formas de hacerlo:
- Desde el panel — Flujo guiado directamente en el Panel
- Con el SDK + API — Integra el flujo de conexión en tu sistema
Conexión desde el panel
Es la forma más sencilla. Entra en el Panel, selecciona el canal que creaste y sigue el flujo de conexión guiado.Conexión con el SDK + API
Usa este flujo cuando quieras que tu usuario conecte el canal desde tu propio sistema, sin necesidad de entrar al panel de . El flujo consta de 3 etapas:1
Frontend — Iniciar la conexión con el SDK
En el frontend de tu aplicación, usa el SDK para iniciar el flujo de conexión. El SDK abrirá el proceso de autenticación con WhatsApp y devolverá la información necesaria.
import OmniZapi from '@omni-zapi/connect';
const client = OmniZapi.newClient({
publicKey: 'SU_PUBLIC_KEY'
});
const response = await client.connect({
channelId: 'ID_DEL_CANAL'
});
// Envía el response a tu backend
La
publicKey se puede exponer en el frontend. Más información en Autenticación.2
Frontend → Backend — Enviar los datos
El SDK devuelve un objeto con la información de la conexión. Envía esos datos al backend de tu aplicación:
{
"wabaId": "428083093730937",
"phoneId": "123456789012345",
"code": "ABC123DEF456",
"coexistence": false
}
| Campo | Tipo | Descripción |
|---|---|---|
wabaId | string | ID de la cuenta de WhatsApp Business seleccionada |
phoneId | string | ID del número de teléfono seleccionado |
code | string | Código de autorización generado por WhatsApp |
coexistence | boolean | Indica si el número está en modo de coexistencia |
3
Backend — Finalizar la conexión mediante la API
En el backend, llama a la API de conexión enviando los datos recibidos del frontend:
POST /v1/channels/{channelId}/connectcurl -X POST https://api.omni.z-api.io/v1/channels/ID_DEL_CANAL/connect \
-H "Content-Type: application/json" \
-H "Authorization: Bearer SU_SECRET_KEY" \
-d '{
"wabaId": "428083093730937",
"phoneId": "123456789012345",
"code": "ABC123DEF456",
"coexistence": false
}'
Esta llamada debe hacerse en el backend, ya que utiliza la Secret Key, que nunca debe exponerse en el frontend.
Flujo resumido
Frontend (SDK) → Backend (API)
1. client.connect()
2. El usuario se autentica
3. El SDK devuelve datos -→ 4. POST /v1/channels/{id}/connect
con wabaId, phoneId, code, coexistence
5. Canal conectado ✓
Una vez establecida la conexión, el canal está listo para enviar y recibir mensajes. Usa el
channelId en los endpoints de mensajes libres y plantillas.Autorizaciones
Secret Key generada en el panel de Seguridad de Omni Z-API
Parámetros de ruta
ID del canal (obtenido con Crear canal)
Ejemplo:
"a1b2c3d4-e5f6-7890-abcd-ef1234567890"
Cuerpo
application/json
Respuesta
Canal conectado correctamente
Indica si la operación se realizó correctamente