API リファレンス
SirrChat は、プログラムによる管理と統合のための RESTful API を提供します。
注意: API 機能は現在開発中であり、一部のエンドポイントは変更される可能性があります。
認証
API キー
認証には API キーを使用します。
API キーを作成
bash
sirrchatd api-key create --user [email protected]出力:
API キー: mk_live_abc123def456ghi789
シークレット: sk_live_xyz789uvw456rst123API キーの使用
http
GET /api/v1/users HTTP/1.1
Host: mail.example.com:8080
Authorization: Bearer mk_live_abc123def456ghi789エンドポイント
ベース URL
https://mail.example.com:8080/api/v1ユーザー管理
ユーザーをリスト
http
GET /api/v1/usersクエリパラメータ:
page: ページ番号(デフォルト 1)limit: ページあたりのアイテム数(デフォルト 20)domain: ドメインでフィルター
レスポンス:
json
{
"data": [
{
"id": "user123",
"email": "[email protected]",
"quota": 5368709120,
"used": 1073741824,
"created_at": "2025-01-15T10:30:00Z"
}
],
"meta": {
"page": 1,
"limit": 20,
"total": 100
}
}ユーザーを作成
http
POST /api/v1/users
Content-Type: application/json
{
"email": "[email protected]",
"password": "securepassword",
"quota": 5368709120,
"blockchain_address": "0x742d..."
}レスポンス:
json
{
"id": "user456",
"email": "[email protected]",
"created_at": "2025-01-15T11:00:00Z"
}ユーザー情報を取得
http
GET /api/v1/users/{id}ユーザーを更新
http
PUT /api/v1/users/{id}
Content-Type: application/json
{
"quota": 10737418240,
"password": "newpassword"
}ユーザーを削除
http
DELETE /api/v1/users/{id}ドメイン管理
ドメインをリスト
http
GET /api/v1/domainsレスポンス:
json
{
"data": [
{
"id": "domain123",
"name": "example.com",
"users_count": 25,
"created_at": "2025-01-01T00:00:00Z"
}
]
}ドメインを作成
http
POST /api/v1/domains
Content-Type: application/json
{
"name": "newdomain.com"
}ドメインを削除
http
DELETE /api/v1/domains/{id}クォータ管理
クォータ使用量を取得
http
GET /api/v1/users/{id}/quotaレスポンス:
json
{
"quota": 5368709120,
"used": 1073741824,
"percentage": 20.0,
"files_count": 1234
}クォータを設定
http
PUT /api/v1/users/{id}/quota
Content-Type: application/json
{
"quota": 10737418240
}メール管理
メールをリスト
http
GET /api/v1/users/{id}/messagesクエリパラメータ:
mailbox: メールボックス名(INBOX、Sent など)limit: 返すアイテム数offset: オフセット
レスポンス:
json
{
"data": [
{
"uid": 12345,
"from": "[email protected]",
"to": ["[email protected]"],
"subject": "Test Email",
"date": "2025-01-15T10:30:00Z",
"size": 1024,
"flags": ["\\Seen"]
}
]
}メールコンテンツを取得
http
GET /api/v1/users/{id}/messages/{uid}メールを削除
http
DELETE /api/v1/users/{id}/messages/{uid}統計
サーバー統計
http
GET /api/v1/statsレスポンス:
json
{
"uptime": 172800,
"users_total": 1234,
"sessions_active": 42,
"messages_today": 5678,
"storage_used": 134678302720,
"smtp": {
"sent": 2345,
"received": 3333,
"rejected": 12
},
"imap": {
"connections": 42,
"commands": 12345
}
}ユーザー統計
http
GET /api/v1/users/{id}/statsWebhook
Webhook を設定
http
POST /api/v1/webhooks
Content-Type: application/json
{
"url": "https://example.com/webhook",
"events": ["email.received", "email.sent"],
"secret": "webhook_secret"
}Webhook イベント
email.received
json
{
"event": "email.received",
"timestamp": "2025-01-15T10:30:00Z",
"data": {
"user": "[email protected]",
"from": "[email protected]",
"subject": "Email Subject",
"size": 1024
}
}email.sent
json
{
"event": "email.sent",
"timestamp": "2025-01-15T10:30:00Z",
"data": {
"user": "[email protected]",
"to": ["[email protected]"],
"subject": "Email Subject"
}
}エラー処理
エラーレスポンスフォーマット
json
{
"error": {
"code": "invalid_request",
"message": "Invalid email format",
"details": {
"field": "email",
"value": "invalid-email"
}
}
}エラーコード
400 Bad Request: 無効なリクエストパラメータ401 Unauthorized: 未認証403 Forbidden: 権限不足404 Not Found: リソースが見つかりません409 Conflict: リソースの競合429 Too Many Requests: リクエストが多すぎます500 Internal Server Error: サーバーエラー
レート制限
API リクエストはレート制限で保護されています。
制限:
- 認証済みユーザー: 1時間あたり1000リクエスト
- IP アドレス: 1時間あたり100リクエスト
レスポンスヘッダー:
http
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1642179600ページネーション
リストエンドポイントはページネーションをサポート。
クエリパラメータ:
page: ページ番号(1から開始)limit: ページあたりのアイテム数(最大100)
レスポンス:
json
{
"data": [...],
"meta": {
"page": 1,
"limit": 20,
"total": 100,
"total_pages": 5
},
"links": {
"first": "/api/v1/users?page=1",
"last": "/api/v1/users?page=5",
"prev": null,
"next": "/api/v1/users?page=2"
}
}SDK
Go SDK
go
import "github.com/mail-chat-chain/mailchatd-go"
client := sirrchatd.NewClient("mk_live_abc123...")
user, err := client.Users.Get("user123")
if err != nil {
log.Fatal(err)
}
fmt.Printf("User: %s\n", user.Email)Python SDK
python
from sirrchatd import Client
client = Client(api_key="mk_live_abc123...")
user = client.users.get("user123")
print(f"User: {user.email}")JavaScript SDK
javascript
const SirrChatD = require('sirrchatd-js');
const client = new SirrChatD('mk_live_abc123...');
const user = await client.users.get('user123');
console.log(`User: ${user.email}`);例
ユーザーをバッチ作成
bash
curl -X POST https://mail.example.com:8080/api/v1/users/batch \
-H "Authorization: Bearer mk_live_abc123..." \
-H "Content-Type: application/json" \
-d '{
"users": [
{"email": "[email protected]", "password": "pass1"},
{"email": "[email protected]", "password": "pass2"}
]
}'ユーザーリストをエクスポート
bash
curl -X GET "https://mail.example.com:8080/api/v1/users?limit=1000" \
-H "Authorization: Bearer mk_live_abc123..." \
| jq '.data[] | {email, quota, used}'関連ドキュメント: