メインコンテンツへスキップ
8分で読めます

POST /query/:websiteId

プレーンテキストであなたのアナリティクスデータについて質問を投げかけてください。AI エンジンが質問を解釈し、関連するデータをクエリして、人間が読める要約とともに構造化された結果を返します。会話型のアナリティクスインターフェースや自動レポートの構築に最適です。

POST/api/external/v1/query/:websiteId

自然言語アナリティクスクエリ

認証

すべてのリクエストは X-API-Key ヘッダー経由で渡される API キーが必要です。別の方法として、Authorization: Bearer YOUR_API_KEY ヘッダーを使用することもできます。

認証Bash
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?"}'

このエンドポイントは Scale プラン以上が必要です。Pro および Free-tier の API キーは 403 Forbidden レスポンスを受け取ります。

各リクエストは AI 処理により 3 API クレジットがかかります。使用計画に考慮してください。

リクエストボディ

フィールド必須説明
questionstringはいプレーンテキストのアナリティクス質問(最大 500 文字)
contextobjectいいえクエリを絞り込むための追加コンテキスト
context.time_rangestringいいえ時間範囲を上書き: 24h, 7d, 30d, 90d
context.compare_tostringいいえ比較期間: previous_period, previous_year
リクエストボディJSON
{
"question": "What are my top traffic sources this week?",
"context": {
  "time_range": "7d",
  "compare_to": "previous_period"
}
}

レスポンス

レスポンス (200 OK)JSON
{
"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"
}

レスポンスフィールド

フィールド説明
data.questionstring送信された元の質問
data.intentstringAI が検出した意図カテゴリ
data.confidencenumber意図検出の信頼スコア (0-1)
data.time_rangestringクエリに使用された時間範囲
data.resultsobject構造化されたクエリ結果
data.results.typestring結果形式: table, number, timeseries, list
data.results.columnsarray列ヘッダー(table タイプの場合)
data.results.rowsarrayデータ行(table タイプの場合)
data.summarystring結果の AI 生成自然言語要約
data.suggestionsarrayユーザーが聞きたいかもしれないフォローアップ質問

結果タイプ

results.type フィールドはデータがどのように構造化されているかを示します:

タイプ説明フィールド
table列と行を含む表形式データcolumns, rows
number単一のメトリック値value, label, change
timeseries時系列データポイントpoints ({date, value} の配列)
list順序付けられたアイテムのリストitems (文字列の配列)

質問と回答の例

例 1: 単一メトリッククエリ

リクエストJSON
{
"question": "How many unique visitors did I get yesterday?"
}
レスポンスJSON
{
"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"
}

例 2: 時系列クエリ

リクエストJSON
{
"question": "Show me my daily page views trend for the past 2 weeks"
}
レスポンスJSON
{
"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"
}

例 3: 比較クエリ

リクエストJSON
{
"question": "Compare my mobile vs desktop conversion rates this month",
"context": {
  "time_range": "30d",
  "compare_to": "previous_period"
}
}
レスポンスJSON
{
"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"
}

TypeScript インターフェース

QueryResponseTypeScript
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;
}

HTTP ステータスコード

ステータスコード説明
200成功
400不正なリクエスト - 質問がないか無効です
401未認可 - API キーが無効または存在しません
403禁止 - Scale プラン以上が必要です
404見つかりません - ウェブサイトが見つかりません
422処理不可 - 質問が解釈できません
429リクエストが多すぎます - レート制限を超過しました
500内部サーバーエラー

コード例

cURLBash
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"
  }
}'

エラー処理

エラーレスポンス (403 Forbidden)JSON
{
"success": false,
"error": {
  "message": "This endpoint requires a Scale plan or higher",
  "code": "PLAN_REQUIRED",
  "timestamp": "2026-03-16T15:00:00.000Z"
}
}
エラーレスポンス (422 Unprocessable)JSON
{
"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"
}
}
このページは役に立ちましたか?