POST /query/:websiteId
Haz preguntas sobre tus datos analíticos en inglés plano. El motor de IA interpreta tu pregunta, consulta los datos relevantes y devuelve resultados estructurados con un resumen legible para humanos. Ideal para crear interfaces de análisis conversacionales o reportes automatizados.
/api/external/v1/query/:websiteIdConsulta de análisis en lenguaje natural
Autenticación
Todas las solicitudes requieren una clave API pasada a través del encabezado X-API-Key. Alternativamente, puedes usar el encabezado Authorization: Bearer YOUR_API_KEY.
curl -X POST 'https://api.zenovay.com/api/external/v1/query/a1b2c3d4-e5f6-7890-abcd-ef1234567890' \
-H 'X-API-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"question": "What are my top traffic sources this week?"}'Este endpoint requiere un plan Scale o superior. Las claves API de los planes Pro y Free-tier recibirán una respuesta 403 Forbidden.
Cada solicitud cuesta 3 créditos API debido al procesamiento de IA. Ten esto en cuenta en tu planificación de uso.
Cuerpo de la Solicitud
| Campo | Tipo | Requerido | Descripción |
|---|---|---|---|
question | string | Sí | Tu pregunta analítica en inglés plano (máx 500 caracteres) |
context | object | No | Contexto adicional para refinar la consulta |
context.time_range | string | No | Anula el rango de tiempo: 24h, 7d, 30d, 90d |
context.compare_to | string | No | Período de comparación: previous_period, previous_year |
{
"question": "What are my top traffic sources this week?",
"context": {
"time_range": "7d",
"compare_to": "previous_period"
}
}Respuesta
{
"success": true,
"data": {
"question": "What are my top traffic sources this week?",
"intent": "traffic_sources_breakdown",
"confidence": 0.95,
"time_range": "7d",
"results": {
"type": "table",
"columns": ["source", "visitors", "percentage", "change"],
"rows": [
["Google Organic", 4521, 38.2, 12.5],
["Direct", 3102, 26.2, -3.1],
["Twitter", 1845, 15.6, 45.2],
["GitHub", 982, 8.3, 8.7],
["Hacker News", 651, 5.5, 128.3],
["LinkedIn", 432, 3.6, -12.4],
["Other", 305, 2.6, 1.2]
]
},
"summary": "Your top traffic source this week is Google Organic with 4,521 visitors (38.2% of total). Twitter saw the largest relative growth at +45.2%, while Hacker News traffic surged +128.3% compared to last week, likely driven by a front-page post.",
"suggestions": [
"Which pages are Hacker News visitors landing on?",
"What is the bounce rate for Twitter traffic?",
"How does my organic search traffic compare to last month?"
]
},
"timestamp": "2026-03-16T15:00:00.000Z"
}Campos de Respuesta
| Campo | Tipo | Descripción |
|---|---|---|
data.question | string | La pregunta original tal como se envió |
data.intent | string | La categoría de intención detectada por IA |
data.confidence | number | Puntuación de confianza para la detección de intención (0-1) |
data.time_range | string | El rango de tiempo utilizado para la consulta |
data.results | object | Resultados de consulta estructurados |
data.results.type | string | Formato de resultado: table, number, timeseries, list |
data.results.columns | array | Encabezados de columna (para tipo table) |
data.results.rows | array | Filas de datos (para tipo table) |
data.summary | string | Resumen en lenguaje natural generado por IA de los resultados |
data.suggestions | array | Preguntas de seguimiento que el usuario podría querer hacer |
Tipos de Resultado
El campo results.type indica cómo se estructuran los datos:
| Tipo | Descripción | Campos |
|---|---|---|
table | Datos tabulares con columnas y filas | columns, rows |
number | Valor de métrica única | value, label, change |
timeseries | Puntos de datos a lo largo del tiempo | points (array de {date, value}) |
list | Lista ordenada de elementos | items (array de strings) |
Ejemplos de Preguntas y Respuestas
Ejemplo 1: Consulta de Métrica Única
{
"question": "How many unique visitors did I get yesterday?"
}{
"success": true,
"data": {
"question": "How many unique visitors did I get yesterday?",
"intent": "unique_visitors_count",
"confidence": 0.98,
"time_range": "24h",
"results": {
"type": "number",
"value": 2847,
"label": "Unique Visitors",
"change": 15.3
},
"summary": "You received 2,847 unique visitors yesterday, which is 15.3% higher than the previous day (2,469 visitors). This is above your 7-day average of 2,412 unique daily visitors.",
"suggestions": [
"Where did yesterday's visitors come from?",
"What pages were most popular yesterday?",
"How does yesterday compare to last week?"
]
},
"timestamp": "2026-03-16T15:00:00.000Z"
}Ejemplo 2: Consulta de Series Temporales
{
"question": "Show me my daily page views trend for the past 2 weeks"
}{
"success": true,
"data": {
"question": "Show me my daily page views trend for the past 2 weeks",
"intent": "pageviews_timeseries",
"confidence": 0.92,
"time_range": "14d",
"results": {
"type": "timeseries",
"points": [
{"date": "2026-03-03", "value": 8234},
{"date": "2026-03-04", "value": 9102},
{"date": "2026-03-05", "value": 8876},
{"date": "2026-03-06", "value": 9543},
{"date": "2026-03-07", "value": 7234},
{"date": "2026-03-08", "value": 5102},
{"date": "2026-03-09", "value": 5897},
{"date": "2026-03-10", "value": 9012},
{"date": "2026-03-11", "value": 9456},
{"date": "2026-03-12", "value": 9234},
{"date": "2026-03-13", "value": 10102},
{"date": "2026-03-14", "value": 7654},
{"date": "2026-03-15", "value": 5432},
{"date": "2026-03-16", "value": 6123}
]
},
"summary": "Your daily page views over the past 2 weeks average 7,857. There is a clear weekly pattern with dips on weekends (Saturday-Sunday). The highest traffic day was March 13 with 10,102 page views, and overall the trend is slightly upward at +4.2% week-over-week.",
"suggestions": [
"Why did traffic dip on March 7?",
"What drove the spike on March 13?",
"How do weekday vs weekend patterns compare?"
]
},
"timestamp": "2026-03-16T15:00:00.000Z"
}Ejemplo 3: Consulta Comparativa
{
"question": "Compare my mobile vs desktop conversion rates this month",
"context": {
"time_range": "30d",
"compare_to": "previous_period"
}
}{
"success": true,
"data": {
"question": "Compare my mobile vs desktop conversion rates this month",
"intent": "device_conversion_comparison",
"confidence": 0.91,
"time_range": "30d",
"results": {
"type": "table",
"columns": ["device", "conversion_rate", "previous_rate", "change"],
"rows": [
["Desktop", 3.8, 3.5, 8.6],
["Mobile", 1.9, 2.1, -9.5],
["Tablet", 2.4, 2.3, 4.3]
]
},
"summary": "Desktop has the highest conversion rate at 3.8% (+8.6% vs last month), while mobile conversion dropped to 1.9% (-9.5%). The gap between desktop and mobile widened this month, suggesting mobile checkout or landing page experience may need attention.",
"suggestions": [
"Which mobile pages have the highest drop-off?",
"What is the average page load time on mobile?",
"Show me the mobile conversion funnel breakdown"
]
},
"timestamp": "2026-03-16T15:00:00.000Z"
}Interfaz de TypeScript
interface TableResults {
type: 'table';
columns: string[];
rows: (string | number)[][];
}
interface NumberResults {
type: 'number';
value: number;
label: string;
change: number;
}
interface TimeseriesResults {
type: 'timeseries';
points: { date: string; value: number }[];
}
interface ListResults {
type: 'list';
items: string[];
}
type QueryResults = TableResults | NumberResults | TimeseriesResults | ListResults;
interface QueryResponse {
success: true;
data: {
question: string;
intent: string;
confidence: number;
time_range: string;
results: QueryResults;
summary: string;
suggestions: string[];
};
timestamp: string;
}Códigos de Estado HTTP
| Código de Estado | Descripción |
|---|---|
| 200 | Éxito |
| 400 | Solicitud Incorrecta - Pregunta faltante o inválida |
| 401 | No Autorizado - Clave API inválida o faltante |
| 403 | Prohibido - Se requiere plan Scale o superior |
| 404 | No Encontrado - Sitio web no encontrado |
| 422 | Entidad No Procesable - La pregunta no pudo ser interpretada |
| 429 | Demasiadas Solicitudes - Límite de velocidad excedido |
| 500 | Error Interno del Servidor |
Ejemplos de Código
curl -X POST 'https://api.zenovay.com/api/external/v1/query/a1b2c3d4-e5f6-7890-abcd-ef1234567890' \
-H 'X-API-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"question": "What are my top traffic sources this week?",
"context": {
"time_range": "7d",
"compare_to": "previous_period"
}
}'Manejo de Errores
{
"success": false,
"error": {
"message": "This endpoint requires a Scale plan or higher",
"code": "PLAN_REQUIRED",
"timestamp": "2026-03-16T15:00:00.000Z"
}
}{
"success": false,
"error": {
"message": "Unable to interpret the question. Please rephrase or be more specific.",
"code": "QUERY_UNPROCESSABLE",
"timestamp": "2026-03-16T15:00:00.000Z"
}
}