Neo Bazi Solutions 四柱推命 API 仕様書

エンドポイント

GET POST https://api.nbs.jp/v1/calculate

四柱推命の計算結果を取得します。

認証

APIキーによる認証が必要です。以下のいずれかの方法でAPIキーを提供してください。

方法1: URLパラメーター (GET/POST リクエスト) - 最も確実:

?api_key=YOUR_API_KEY&year=1974&month=10&day=3&hour=11&location=139.75

方法2: JSONボディ内 (POST リクエスト) - 推奨:

{ "api_key": "YOUR_API_KEY", "year": 1974, "month": 10, "day": 3, "hour": 11, "location": 139.75 }

方法3: Authorization ヘッダー (GET/POST リクエスト):

Authorization: Bearer YOUR_API_KEY

方法4: X-API-Key ヘッダー (GET/POST リクエスト):

X-API-Key: YOUR_API_KEY
📝 Note: APIキーはダッシュボードで確認できます。
⚠️ 重要: ブラウザから直接アクセスする場合、AuthorizationとX-API-Keyヘッダーが空になるため、URLパラメータまたはJSONボディでのAPIキー送信をお勧めします。JavaScript(fetch/XMLHttpRequest)からはすべての方法が正常に動作します。

リクエストパラメータ

以下のパラメータを送信してください。GETリクエストの場合はURLクエリパラメータ、POSTリクエストの場合はapplication/json形式のリクエストボディとして送信します。

パラメータ名 必須 説明
year integer 必須 西暦年 (例: 1990)
month integer 必須 月 (1-12) (例: 5)
day integer 必須 日 (1-31) (例: 15)
location float 必須 経度 (東経を正の値で指定) (例: 139.6917)
hour integer 任意 時 (0-23)。time パラメータが指定されている場合は無視されます。
minute integer 任意 分 (0-59)。time パラメータが指定されている場合は無視されます。デフォルトは0です。
time string 任意 時刻を HH:MM 形式で指定します (例: "14:30")。hour, minute より優先されます。時刻が指定されない場合、デフォルトで "12:00" が使用されます。
api_key string 任意 APIキー。URLパラメータまたはJSONボディで送信します。ヘッダー認証より優先されます。

レスポンス

成功した場合、以下の構造を持つJSONオブジェクトを返します。

{
"status": "success",
"message": "API処理が正常に完了しました。",
"credits_consumed": 10,
"credits_remaining": 1120,
"monthly_credits": 1110,
"auto_credits": 10,
"credits_used_from": {
"monthly": 10,
"auto": 0
},
"autocharge_info": {
"success": true,
"message": "Total credits above threshold",
"debug": {
"monthly_credits": 1120,
"auto_credits": 10,
"total_credits": 1130,
"threshold": 100
}
},
"result": {
"input_date": "1974-10-03 11:00",
"input_longitude": 139.75,
"true_solar_time": "1974-10-03 11:19",
"spring_date": "1974-02-04 14:00",
"year_ganzhi": "甲寅",
"month_ganzhi": "癸酉",
"day_ganzhi": "丁丑",
"time_ganzhi": "丙午",
"month_ganzhi_date": "1974-09-08 09:45",
"month_ganzhi_biko": "白露(黄経165°)",
"julian_day": 2442323,
"day_ganzhi_details": {
"number": 14,
"element": "火",
"yin_yang": "陰-",
"heavenly_stem": "丁",
"earthly_branch_group": "申酉",
"star": "天庫星",
"animal": "ひつじ"
},
"ten_gods": {
"year": "印綬",
"month": "偏官",
"time": "劫財"
},
"zokan": {
"year": "甲",
"month": "辛",
"day": "己",
"time": "丁"
},
"zokan_ten_gods": {
"year": "印綬",
"month": "偏財",
"day": "食神",
"time": "比肩"
},
"juniun": {
"year": "死",
"month": "長生",
"day": "墓",
"time": "建禄"
},
"nayin": [],
"gogyo_balance": {
"木": 2,
"火": 3,
"土": 1,
"金": 1,
"水": 1
},
"summary": {
"day_master": "丁丑",
"element": "火",
"strength": "中",
"fortune_score": 70,
"personality_traits": [
"繊細"
]
}
},
"transaction_id": null,
"log_id": "1751616830"
}
📝 Note: result オブジェクト内のキーの順序は上記と異なる場合があります。

エラーレスポンス

エラーが発生した場合、以下の構造を持つJSONオブジェクトを返します。

{
"status": "error",
"message": "エラーメッセージ"
}

クレジット消費

API呼び出しごとに 10クレジット が消費されます。Enterpriseプランのユーザーはクレジットを消費しません。

サンプルコード

APIを利用するためのサンプルコードです。YOUR_API_KEY をご自身のAPIキーに置き換えてください。

🚀 WordPress対応: WordPress対応の四柱推命API「Neo Bazi Solutions」で高精度命式が簡単に!
WordPressサイトでの実装方法とプラグイン開発について詳しく解説しています。

cURL (Bash) - GET リクエスト

curl "https://api.nbs.jp/v1/calculate?api_key=YOUR_API_KEY&year=1974&month=10&day=3&hour=11&location=139.75"

cURL (Bash) - POST リクエスト (推奨)

curl -X POST "https://api.nbs.jp/v1/calculate" \
-H "Content-Type: application/json" \
-d '{
"api_key": "YOUR_API_KEY",
"year": 1974,
"month": 10,
"day": 3,
"hour": 11,
"location": 139.75
}'

cURL (Bash) - POST リクエスト (ヘッダー認証)

curl -X POST "https://api.nbs.jp/v1/calculate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"year": 1974,
"month": 10,
"day": 3,
"hour": 11,
"location": 139.75
}'

JavaScript (Node.js) - GET リクエスト

const axios = require('axios');

const calculateBazi = async () => {
try {
const response = await axios.get('https://api.nbs.jp/v1/calculate', {
params: {
api_key: 'YOUR_API_KEY',
year: 1974,
month: 10,
day: 3,
hour: 11,
location: 139.75
}
});

return response.data;
} catch (error) {
console.error('Error:', error.response.data);
throw error;
}
};

calculateBazi()
.then(result => console.log(result))
.catch(error => console.error(error));

JavaScript (Node.js) - POST リクエスト

const axios = require('axios');

const calculateBazi = async () => {
try {
const response = await axios.post('https://api.nbs.jp/v1/calculate', {
year: 1974,
month: 10,
day: 3,
hour: 11,
location: 139.75
}, {
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
});

return response.data;
} catch (error) {
console.error('Error:', error.response.data);
throw error;
}
};

calculateBazi()
.then(result => console.log(result))
.catch(error => console.error(error));

Python - GET リクエスト

import requests

api_key = 'YOUR_API_KEY'
url = 'https://api.nbs.jp/v1/calculate'
params = {
'api_key': api_key,
'year': 1974,
'month': 10,
'day': 3,
'hour': 11,
'location': 139.75
}

response = requests.get(url, params=params)

if response.status_code == 200:
result = response.json()
print(json.dumps(result, indent=2, ensure_ascii=False))
else:
print(f"APIリクエストエラー: {response.status_code}")
print(response.text)

Python - POST リクエスト

import requests
import json

api_key = 'YOUR_API_KEY'
url = 'https://api.nbs.jp/v1/calculate'
data = {
'year': 1974,
'month': 10,
'day': 3,
'hour': 11,
'location': 139.75
}

headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}

response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
result = response.json()
print(json.dumps(result, indent=2, ensure_ascii=False))
else:
print(f"APIリクエストエラー: {response.status_code}")
print(response.text)

備考

現在サポート中の機能

今後拡張予定の機能

💡 Tips: 高精度な四柱推命計算のため、可能な限り正確な出生時刻と出生地の経度をご指定ください。