Rocket.net API 連携
Rocket.net のマネージド WordPress ホスティングプラットフォーム API との連携を構築します。このスキルでは、認証、サイト管理、ドメイン設定、バックアップ、プラグイン/テーマ、CDN キャッシュ制御、および 200 以上のすべての API エンドポイントを扱います。
API の概要
ベース URL:https://api.rocket.net/v1
認証:JWT トークンベース
- メールアドレスとパスワードを指定して POST
/login を実行し、トークンを取得します
- トークンの有効期限は 7 日間です
- リクエストでは
Authorization: Bearer <token> として指定します
コンテンツタイプ:JSON API
- 必須ヘッダー:
Content-Type: application/json
- 推奨ヘッダー:
Accept: application/json
ドキュメント:https://rocketdotnet.readme.io/reference/introduction
認証
JWT トークンを取得する
const response = await fetch('https://api.rocket.net/v1/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
username: '[email protected]',
password: 'your-password'
})
});
const { token } = await response.json();
// Use token in subsequent requests
認証済みリクエストのパターン
async function rocketApiRequest(
endpoint: string,
options: RequestInit = {}
): Promise<any> {
const response = await fetch(`https://api.rocket.net/v1${endpoint}`, {
...options,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`,
...options.headers
}
});
if (response.status === 401) {
// Token expired, re-authenticate
throw new Error('Token expired - request new token');
}
return response.json();
}
カテゴリ別 API エンドポイント
サイト管理
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites | すべてのサイトを一覧表示 |
| POST | /sites | 新しいサイトを作成 |
| GET | /sites/{id} | サイトの詳細を取得 |
| PATCH | /sites/{id} | サイトのプロパティを更新 |
| DELETE | /sites/{id} | サイトを削除 |
| POST | /sites/{id}/clone | サイトを複製(バックグラウンドタスク) |
| GET | /sites/{id}/credentials | サイトの認証情報を取得 |
| GET | /sites/{id}/usage | サイトの使用状況統計を取得 |
| POST | /sites/{id}/lock | サイトをロック(変更を防止) |
| DELETE | /sites/{id}/lock | サイトのロックを解除 |
| GET | /sites/{id}/pma_login | phpMyAdmin の SSO リンクを取得 |
| GET | /sites/{id}/settings | サイトの設定を取得 |
| PATCH | /sites/{id}/settings | サイトの設定を更新 |
| GET | /sites/locations | 利用可能なサイトのロケーションを一覧表示 |
ステージングサイト
| メソッド | エンドポイント | 説明 |
|---|
| POST | /sites/{id}/staging | ステージングサイトを作成 |
| DELETE | /sites/{id}/staging | ステージングサイトを削除 |
| POST | /sites/{id}/staging/publish | ステージングサイトを本番環境に公開 |
サイトテンプレート
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/templates | サイトテンプレートを一覧表示 |
| POST | /sites/templates | サイトテンプレートを作成 |
| GET | /sites/templates/{id} | テンプレートの詳細を取得 |
| DELETE | /sites/templates/{id} | テンプレートを削除 |
| POST | /sites/templates/{id}/sites | テンプレートからサイトを作成 |
ドメイン
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/domains | ドメインエイリアスを一覧表示 |
| POST | /sites/{id}/domains | ドメインエイリアスを追加 |
| DELETE | /sites/{id}/domains/{domainId} | ドメインエイリアスを削除 |
| GET | /sites/{id}/maindomain | メインドメイン情報を取得 |
| POST | /sites/{id}/maindomain | メインドメインを設定 |
| PUT | /sites/{id}/maindomain | メインドメインを置換 |
| PATCH | /sites/{id}/maindomain | ドメインの検証/SSL を更新 |
| GET | /sites/{id}/maindomain/status | ドメインのステータスを確認 |
| GET | /sites/{id}/maindomain/recheck | 検証を強制的に再確認 |
| GET | /sites/{id}/domains/{domainId}/edge_settings | エッジ設定を取得 |
| PATCH | /sites/{id}/domains/{domainId}/edge_settings | エッジ設定を更新 |
CDN キャッシュ
| メソッド | エンドポイント | 説明 |
|---|
| POST | /sites/{id}/cache/purge | 特定のファイルをキャッシュから削除 |
| POST | /sites/{id}/cache/purge_everything | すべてのキャッシュを削除 |
プラグイン
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/plugins | インストール済みプラグインを一覧表示 |
| POST | /sites/{id}/plugins | プラグインをインストール |
| PATCH | /sites/{id}/plugins | プラグインを有効化/無効化 |
| PUT | /sites/{id}/plugins | プラグインを更新 |
| DELETE | /sites/{id}/plugins | プラグインを削除 |
| GET | /sites/{id}/plugins/search | 利用可能なプラグインを検索 |
| GET | /sites/{id}/featured_plugins | おすすめのプラグインを一覧表示 |
テーマ
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/themes | インストール済みテーマの一覧 |
| POST | /sites/{id}/themes | テーマをインストール |
| PATCH | /sites/{id}/themes | テーマを有効化 |
| PUT | /sites/{id}/themes | テーマを更新 |
| DELETE | /sites/{id}/themes | テーマを削除 |
| GET | /sites/{id}/themes/search | 利用可能なテーマを検索 |
バックアップ
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/backup | バックアップの一覧 |
| POST | /sites/{id}/backup | バックアップを作成 |
| GET | /sites/{id}/backup/{backupId} | バックアップをダウンロード |
| DELETE | /sites/{id}/backup/{backupId} | バックアップを削除 |
| POST | /sites/{id}/backup/{backupId}/restore | バックアップを復元 |
| GET | /sites/{id}/backup/automated | 自動バックアップの一覧 |
| POST | /sites/{id}/backup/automated/{restoreId}/restore | 自動バックアップを復元 |
クラウドバックアップ
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/cloud_backups | クラウドバックアップの一覧 |
| POST | /sites/{id}/cloud_backups | クラウドバックアップを作成 |
| GET | /sites/{id}/cloud_backups/{backupId} | クラウドバックアップを取得 |
| DELETE | /sites/{id}/cloud_backups/{backupId} | クラウドバックアップを削除 |
| GET | /sites/{id}/cloud_backups/{backupId}/download | ダウンロードリンクを取得 |
| POST | /sites/{id}/cloud_backups/{backupId}/restore | クラウドバックアップを復元 |
ファイル
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/file_manager/files | ファイルの一覧 |
| POST | /sites/{id}/files | ファイルをアップロード |
| PUT | /sites/{id}/files | ファイルの内容を保存 |
| DELETE | /sites/{id}/files | ファイルを削除 |
| GET | /sites/{id}/files/view | ファイルの内容を表示 |
| GET | /sites/{id}/files/download | ファイルをダウンロード |
| POST | /sites/{id}/files/folder | フォルダーを作成 |
| POST | /sites/{id}/files/extract | アーカイブを展開 |
| POST | /sites/{id}/files/compress | ファイルを圧縮 |
| PATCH | /sites/{id}/files/chmod | 権限を変更 |
FTP アカウント
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/ftp_accounts | FTP アカウントの一覧 |
| POST | /sites/{id}/ftp_accounts | FTP アカウントを作成 |
| PATCH | /sites/{id}/ftp_accounts | FTP アカウントを更新 |
| DELETE | /sites/{id}/ftp_accounts | FTP アカウントを削除 |
SSH キー
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/ssh_keys | SSH キーの一覧 |
| POST | /sites/{id}/ssh_keys | SSH キーをインポート |
| DELETE | /sites/{id}/ssh_keys | SSH キーを削除 |
| POST | /sites/{id}/ssh_keys/authorize | SSH キーを有効化 |
| POST | /sites/{id}/ssh_keys/deauthorize | SSH キーを無効化 |
| GET | /sites/{id}/ssh_keys/{name} | SSH キーの情報を表示 |
WordPress
| メソッド | エンドポイント | 説明 |
|---|
| GET | /sites/{id}/wp_login | WordPress の SSO リンクを取得 |
| GET | /sites/{id}/wp_status | WordPress のステータスを取得 |
| POST | /sites/{id}/wpcli | WP-CLI コマンドを実行 |
レポート
| メソッド | エンドポイント | 説明 |
|---|
| GET | /reporting/sites/{id}/cdn_requests | CDN リクエストレポート |
| GET | /reporting/sites/{id}/cdn_cache_status | キャッシュステータスレポート |
| GET | /reporting/sites/{id}/cdn_cache_content | キャッシュコンテンツレポート |
| GET | /reporting/sites/{id}/visitors | 訪問者レポート |
| GET | /reporting/sites/{id}/waf_eventlist | WAF イベント一覧 |
| GET | /reporting/sites/{id}/waf_events_source | ソース別 WAF イベント |
| GET | /reporting/sites/{id}/waf_firewall_events | ファイアウォールイベント |
| GET | /reporting/sites/{id}/bandwidth_usage | 帯域幅使用量 |
| GET | /reporting/sites/{id}/bandwidth_top_usage | 帯域幅使用量の上位 |
| GET | /sites/{id}/access_logs | アクセスログ |
アカウント管理
| Method | Endpoint | Description |
|---|
| GET | /account/me | ユーザー情報を取得 |
| PATCH | /account/me | アカウント設定を更新 |
| GET | /account/usage | アカウントの使用状況を取得 |
| POST | /account/password | パスワードを変更 |
| GET | /account/tasks | アカウントのタスク一覧を取得 |
| GET | /account/hosting_plan | 現在のプランを取得 |
| PUT | /account/hosting_plan | ホスティングプランを変更 |
| POST | /account/billing_sso | 請求用 SSO Cookie を取得 |
アカウントユーザー
| Method | Endpoint | Description |
|---|
| GET | /users | アカウントユーザーの一覧を取得 |
| POST | /users | アカウントユーザーを作成 |
| GET | /users/{userId} | ユーザーの詳細を取得 |
| PATCH | /users/{userId} | ユーザーを更新 |
| DELETE | /users/{userId} | ユーザーを削除 |
| POST | /users/{userId}/reinvite | 招待を再送信 |
サイトユーザー
| Method | Endpoint | Description |
|---|
| GET | /sites/{id}/users | サイトユーザーの一覧を取得 |
| POST | /sites/{id}/users | サイトユーザーを招待 |
| DELETE | /sites/{id}/users/{userId} | サイトユーザーを削除 |
| POST | /sites/{id}/users/{userId}/reinvite | 招待を再送信 |
請求
| Method | Endpoint | Description |
|---|
| GET | /billing/addresses | 請求先住所の一覧を取得 |
| POST | /billing/addresses | 請求先住所を作成 |
| GET | /billing/addresses/{addressId} | 請求先住所を取得 |
| PATCH | /billing/addresses/{addressId} | 請求先住所を更新 |
| DELETE | /billing/addresses/{addressId} | 請求先住所を削除 |
| GET | /billing/invoices | 請求書の一覧を取得 |
| GET | /billing/invoices/{invoiceId} | 請求書を取得 |
| GET | /billing/invoices/{invoiceId}/pdf | 請求書の PDF をダウンロード |
| POST | /billing/invoices/{invoiceId}/credit_card_payment | カードで支払う |
| GET | /billing/payment_methods | 支払い方法の一覧を取得 |
| POST | /billing/payment_methods | 支払い方法を追加 |
| DELETE | /billing/payment_methods/{methodId} | 支払い方法を削除 |
| GET | /billing/products | 利用可能な製品の一覧を取得 |
その他の機能
| Method | Endpoint | Description |
|---|
| GET | /sites/{id}/password_protection | パスワード保護の状態を取得 |
| POST | /sites/{id}/password_protection | パスワード保護を有効化 |
| DELETE | /sites/{id}/password_protection | パスワード保護を無効化 |
| GET | /sites/{id}/shopshield | ShopShield URI の一覧を取得 |
| POST | /sites/{id}/shopshield | ShopShield を有効化 |
| DELETE | /sites/{id}/shopshield/{id} | ShopShield を無効化 |
| GET | /account/visitors | アカウントの訪問者統計 |
| GET | /account/bandwidth | アカウントの帯域幅統計 |
よく使うパターン
すべてのサイトを一覧表示
const sites = await rocketApiRequest('/sites');
console.log(sites);
// Returns array of site objects with id, domain, status, etc.
新しいサイトを作成
const newSite = await rocketApiRequest('/sites', {
method: 'POST',
body: JSON.stringify({
name: 'my-new-site',
location: 'us-east-1',
// Additional options as needed
})
});
CDN キャッシュを消去
// Purge specific URLs
await rocketApiRequest(`/sites/${siteId}/cache/purge`, {
method: 'POST',
body: JSON.stringify({
files: [
'https://example.com/style.css',
'https://example.com/script.js'
]
})
});
// Purge everything
await rocketApiRequest(`/sites/${siteId}/cache/purge_everything`, {
method: 'POST'
});
バックアップを作成して復元
// Create backup
const backup = await rocketApiRequest(`/sites/${siteId}/backup`, {
method: 'POST'
});
// List backups
const backups = await rocketApiRequest(`/sites/${siteId}/backup`);
// Restore backup (background task)
await rocketApiRequest(`/sites/${siteId}/backup/${backupId}/restore`, {
method: 'POST'
});
プラグインを管理
// List installed plugins
const plugins = await rocketApiRequest(`/sites/${siteId}/plugins`);
// Install plugin
await rocketApiRequest(`/sites/${siteId}/plugins`, {
method: 'POST',
body: JSON.stringify({
plugins: ['wordfence', 'yoast-seo']
})
});
// Update all plugins
await rocketApiRequest(`/sites/${siteId}/plugins`, {
method: 'PUT',
body: JSON.stringify({
plugins: ['all']
})
});
// Activate/deactivate plugin
await rocketApiRequest(`/sites/${siteId}/plugins`, {
method: 'PATCH',
body: JSON.stringify({
plugins: ['wordfence'],
action: 'activate' // or 'deactivate'
})
});
WP-CLI コマンドを実行
const result = await rocketApiRequest(`/sites/${siteId}/wpcli`, {
method: 'POST',
body: JSON.stringify({
command: 'user list --format=json'
})
});
WordPress SSO ログイン
// Get SSO link for WordPress admin
const { url } = await rocketApiRequest(`/sites/${siteId}/wp_login`);
// Redirect user to url for auto-login
TypeScript 型
interface RocketSite {
id: number;
name: string;
domain: string;
status: 'active' | 'suspended' | 'pending';
location: string;
created_at: string;
updated_at: string;
}
interface RocketBackup {
id: number;
site_id: number;
type: 'manual' | 'automated' | 'cloud';
status: 'pending' | 'completed' | 'failed';
size: number;
created_at: string;
}
interface RocketPlugin {
name: string;
slug: string;
version: string;
status: 'active' | 'inactive';
update_available: boolean;
}
interface RocketDomain {
id: number;
domain: string;
is_main: boolean;
ssl_status: 'pending' | 'active' | 'failed';
validation_method: 'dns' | 'http';
}
interface RocketAuthResponse {
token: string;
expires_at: string;
}
エラー処理
interface RocketApiError {
error: string;
message: string;
status: number;
}
async function handleRocketRequest(endpoint: string, options?: RequestInit) {
try {
const response = await rocketApiRequest(endpoint, options);
return { data: response, error: null };
} catch (error) {
if (error.status === 401) {
// Re-authenticate and retry
await refreshToken();
return handleRocketRequest(endpoint, options);
}
if (error.status === 404) {
return { data: null, error: 'Resource not found' };
}
if (error.status === 429) {
// Rate limited - wait and retry
await sleep(1000);
return handleRocketRequest(endpoint, options);
}
return { data: null, error: error.message };
}
}
バックグラウンドタスク
クローン、バックアップの復元、ステージングの公開など、多くの操作はバックグラウンドタスクとして実行されます。タスクの状態を監視してください。
// Start a background task
const { task_id } = await rocketApiRequest(`/sites/${siteId}/clone`, {
method: 'POST',
body: JSON.stringify({ name: 'cloned-site' })
});
// Check task status
const tasks = await rocketApiRequest(`/sites/${siteId}/tasks`);
const task = tasks.find(t => t.id === task_id);
console.log(task.status); // 'pending', 'running', 'completed', 'failed'
// Cancel task if needed
await rocketApiRequest(`/sites/${siteId}/tasks/${task_id}/cancel`, {
method: 'POST'
});
レート制限
API にはレート制限があります。指数バックオフを実装してください。
async function withRetry<T>(
fn: () => Promise<T>,
maxRetries = 3,
delay = 1000
): Promise<T> {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (error.status === 429 && i < maxRetries - 1) {
await new Promise(resolve => setTimeout(resolve, delay * Math.pow(2, i)));
continue;
}
throw error;
}
}
throw new Error('Max retries exceeded');
}
参考資料