Webhooks
curl --request POST \
--url https://json.ricardofuentes.dev/api/v1/whatsapp/webhook \
--header 'Content-Type: application/json' \
--data '
{
"instance": "<string>",
"url": "<string>",
"events": [
{}
]
}
'import requests
url = "https://json.ricardofuentes.dev/api/v1/whatsapp/webhook"
payload = {
"instance": "<string>",
"url": "<string>",
"events": [{}]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({instance: '<string>', url: '<string>', events: [{}]})
};
fetch('https://json.ricardofuentes.dev/api/v1/whatsapp/webhook', 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://json.ricardofuentes.dev/api/v1/whatsapp/webhook",
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([
'instance' => '<string>',
'url' => '<string>',
'events' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"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://json.ricardofuentes.dev/api/v1/whatsapp/webhook"
payload := strings.NewReader("{\n \"instance\": \"<string>\",\n \"url\": \"<string>\",\n \"events\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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://json.ricardofuentes.dev/api/v1/whatsapp/webhook")
.header("Content-Type", "application/json")
.body("{\n \"instance\": \"<string>\",\n \"url\": \"<string>\",\n \"events\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://json.ricardofuentes.dev/api/v1/whatsapp/webhook")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"instance\": \"<string>\",\n \"url\": \"<string>\",\n \"events\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"event": "message.received",
"instance": "mi-instancia",
"timestamp": 1740000000,
"data": {
"id": "msg_02k...",
"from": "+51999000111",
"type": "text",
"body": "Hola!",
"name": "Juan Pérez"
}
}
API WhatsApp
Webhooks
Configura una URL para recibir eventos de WhatsApp en tiempo real
POST
/
api
/
v1
/
whatsapp
/
webhook
Webhooks
curl --request POST \
--url https://json.ricardofuentes.dev/api/v1/whatsapp/webhook \
--header 'Content-Type: application/json' \
--data '
{
"instance": "<string>",
"url": "<string>",
"events": [
{}
]
}
'import requests
url = "https://json.ricardofuentes.dev/api/v1/whatsapp/webhook"
payload = {
"instance": "<string>",
"url": "<string>",
"events": [{}]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({instance: '<string>', url: '<string>', events: [{}]})
};
fetch('https://json.ricardofuentes.dev/api/v1/whatsapp/webhook', 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://json.ricardofuentes.dev/api/v1/whatsapp/webhook",
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([
'instance' => '<string>',
'url' => '<string>',
'events' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"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://json.ricardofuentes.dev/api/v1/whatsapp/webhook"
payload := strings.NewReader("{\n \"instance\": \"<string>\",\n \"url\": \"<string>\",\n \"events\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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://json.ricardofuentes.dev/api/v1/whatsapp/webhook")
.header("Content-Type", "application/json")
.body("{\n \"instance\": \"<string>\",\n \"url\": \"<string>\",\n \"events\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://json.ricardofuentes.dev/api/v1/whatsapp/webhook")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"instance\": \"<string>\",\n \"url\": \"<string>\",\n \"events\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"event": "message.received",
"instance": "mi-instancia",
"timestamp": 1740000000,
"data": {
"id": "msg_02k...",
"from": "+51999000111",
"type": "text",
"body": "Hola!",
"name": "Juan Pérez"
}
}
Body
string
required
Nombre de la instancia de WhatsApp
string
required
URL de tu servidor que recibirá los eventos
array
required
Lista de eventos a recibir
Eventos disponibles
| Evento | Descripción |
|---|---|
message.received | Mensaje entrante recibido |
message.delivered | Mensaje entregado al destinatario |
message.read | Mensaje leído por el destinatario |
instance.connected | Instancia conectada |
instance.disconnected | Instancia desconectada |
Ejemplo de configuración
cURL
curl -X POST https://json.ricardofuentes.dev/api/v1/whatsapp/webhook \
-H "Authorization: Bearer tu_token" \
-H "Content-Type: application/json" \
-d '{
"instance": "mi-instancia",
"url": "https://tu-servidor.com/webhook",
"events": ["message.received", "message.delivered"]
}'
Payload que recibirás
Cuando ocurra un evento, tu servidor recibirá un POST con este payload:{
"event": "message.received",
"instance": "mi-instancia",
"timestamp": 1740000000,
"data": {
"id": "msg_02k...",
"from": "+51999000111",
"type": "text",
"body": "Hola!",
"name": "Juan Pérez"
}
}
⌘I