最終更新 2026-07-15
APIリファレンス
概要
meridian API を統合する開発者・運営者向け — 一般訪問者はスキップ可。全 API ルートは src/app/api/ 下の Next.js App Router ハンドラ。天気と geocode は OPENWEATHER_API_KEY 必須。Cron ルートは Authorization: Bearer CRON_SECRET。管理ルートは /login 後の認証済み管理セッション cookie(meridian_admin_session)、開発時は ALLOW_DEV_ADMIN_BYPASS を除く。
GET /api/weather
Query:lat、lon、scope(current|hourly|daily|minutely)、任意 trigger、lang。天気 payload と fetchedAt、cacheHit、freshness、source、trigger、tokensUsed を返す。X-Cache ヘッダーはキャッシュ層を反映。エラー:400 invalid params、404 location not found、429 rate_limited、502 upstream_error または service_unavailable。
POST /api/weather/batch
Body:{ cities: [{ lat, lon, scopes?: string[], id?, lang?, maxAgeMs?, trigger? }], trigger?, lang? }。{ cities: [{ lat, lon, scopes: { scope: { data, meta } | { error } } }] } を返す。スコープは都市ごと、トップレベル配列ではない。IP あたり20リクエスト/分。ダッシュボードと都市詳細フックが使用。
GET /api/weather/history
Query:lat、lon、任意 from/to(ISO 日付)、limit。weather_observations と weather_forecast_archive から { summary, observations, forecasts: { hourly, daily } } を返す。
GET /api/geocode
Query:q(最低2文字)、任意 context パラメータ。正規化配列:name、country、state、lat、lon、label。upstream limit 5。geocode スコープで L2 キャッシュ。IP あたり60リクエスト/分。
GET /api/recent-checks
パラメータなし。{ checks, source } を返す。source は検索トリガー行があるとき popular、なければ empty。既定 limit 20、location_weather_checks を検索量でランク(search_select と search_preview triggers)。API に showcase フォールバックなし — SHOW_DEMO_POPULAR_SEARCHES オンならホーム UI は空時にデモ人気都市を表示しうる。お近く列はこのルートを使わない。
/api/subscriptions
GET ?clientId= — クライアントのアクティブ購読一覧。POST — 作成 { clientId, email, type, cityName?, cityLat?, cityLon?, frequency?, alertOnRain?, alertOnStorm?, alertPrefs? }。PATCH — city_alerts 行の alertPrefs 更新 { clientId, id, alertPrefs }。DELETE — body { clientId, cityLat, cityLon, types[] }。Types:newsletter、city_weekly、city_alerts。
GET /api/unsubscribe
Query:token(unsubscribe_token UUID)。購読を無効化し HTML 確認を返す。
GET /api/alerts/[alertId]
正規化アラート:id、senderName、event、start、end、description。ソース:キャッシュされた alert スコープ。
Cron ルート
GET /api/cron/weekly-digests — 購読者メールごとに週次ダイジェストを送信。GET /api/cron/weather-alerts — alertPrefs を OpenWeather、Open-Meteo、NWS フィードと照合しアラートメール送信。両方 Bearer CRON_SECRET 必須。
管理ルート
利用と設定:GET /api/admin/usage;GET|PATCH /api/admin/config;レガシー PATCH /api/admin/settings { refreshIntervalMs }。ユーザーと認証:GET|POST /api/admin/users;POST /api/admin/users/invite;GET /api/admin/me。データ:GET /api/admin/checks;GET /api/admin/locations;GET|PATCH /api/admin/subscriptions;GET /api/admin/mailing-summary;GET /api/admin/analytics。コネクタ:GET|PATCH /api/admin/connections;GET|PATCH /api/admin/openweather-key;GET|PATCH /api/admin/email-key。メール CMS:GET|POST|PATCH /api/admin/email-templates;POST /api/admin/email/test、/compose、/sync。AdSense:GET /api/admin/adsense/report;POST /api/admin/adsense/sync;OAuth GET /api/admin/adsense/oauth/start、/callback、/disconnect。CMS:GET|PATCH /api/admin/cms-pages。dev bypass を除きすべて meridian_admin_session 必須。
広告ルート
GET /api/ads/config — { scriptEnabled, clientId, consentRequired }。GET /api/ads?placement=dashboard|hero|recent-checks|city-detail — 設定時 slotId 付き配置設定。GET /api/ads/placeholder-bg — プレースホルダー面用ヒーロー lookup。App ルート GET /ads.txt — env から AdSense パブリッシャー行。アクティブ AdSlot 配置:dashboard、hero、city-detail。recent-checks スロット env はあるがホームに AdSlot なし。
その他の公開ルート
GET /api/platform/limits — 公開クォータスナップショット。POST /api/analytics/collect — ファーストパーティ analytics beacon。GET /api/location/region — IP/地域ヘルパー。POST /api/weather/inaccurate-report — 不正確データの報告。GET /api/weather/map-tile/[layer]/[z]/[x]/[y] — OSM ヒーローオーバーレイタイル。Auth:POST /api/auth/login、/logout;POST /api/auth/forgot-password;POST /api/auth/reset-password/[token];GET|POST /api/auth/invite/[token];GET /api/auth/session。
エラー形式
JSON エラーは通常 { error: code, message: string }。ApiError コードに invalid_request、service_unavailable、location_not_found、rate_limited、upstream_error、unauthorized、not_found、limit_reached。