API リファレンス
iwa-cms の公開APIを使って、フロントエンドサイトやアプリケーションからコンテンツを取得できます。
認証
すべてのAPIリクエストには、APIキーによる認証が必要です。
ヘッダー
X-API-Key: your_api_key_hereAPIキーの取得
- 管理画面にログイン
- サービスを選択
- 「APIキー」メニューから新規作成
詳細は APIキー管理 を参照してください。
ベースURL
https://your-domain/api/v1エンドポイント一覧
| メソッド | パス | 説明 |
|---|---|---|
| GET | /{endpoint} | コンテンツ一覧を取得 |
| GET | /{endpoint}/{contentId} | コンテンツ詳細を取得 |
| GET | /categories | カテゴリ一覧を取得 |
endpoint について
{endpoint} にはエンドポイントの パス名(path_name)を指定します。 例: news, blog, products など、管理画面で設定したパス名を使用します。
コンテンツ一覧の取得
公開済みのコンテンツ一覧を取得します。
リクエスト
GET /api/v1/{endpoint}パスパラメータ
| パラメータ | 型 | 説明 |
|---|---|---|
endpoint | string | エンドポイントのパス名(例: news, blog) |
クエリパラメータ
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
filters | string | No | フィルタ条件(例: category[equals]cat123) |
limit | number | No | 取得件数(デフォルト: 10、最大: 100) |
offset | number | No | オフセット(ページネーション用) |
フィルタ構文
microCMS互換のフィルタ構文をサポートしています。
filters=category[equals]カテゴリIDレスポンス
json
{
"contents": [
{
"id": "I-ChEjtNOf",
"endpoint_id": "news",
"title": "お知らせタイトル",
"data": {
"blocks": [
{
"id": "block1",
"type": "heading",
"content": "見出し",
"attrs": { "level": 1 }
},
{
"id": "block2",
"type": "paragraph",
"content": "本文テキスト"
},
{
"id": "block3",
"type": "list",
"content": "リストアイテム",
"attrs": { "ordered": false }
}
]
},
"category_ids": ["cat_123"],
"published_at": "2025-12-15T12:00:00Z",
"created_at": "2025-12-14T10:00:00Z",
"updated_at": "2025-12-15T12:00:00Z"
}
],
"total_count": 42,
"limit": 10,
"offset": 0
}ブロックタイプ
| type | 説明 | attrs |
|---|---|---|
heading | 見出し | level: 1-3 |
paragraph | 段落 | - |
list | リスト | ordered: true/false |
image | 画像 | url, alt |
code | コードブロック | language |
table | テーブル | rows: string[][] |
インラインスタイル
content には <bold>, <italic>, <underline>, <strike> タグが含まれる場合があります。
"content": "通常テキスト<bold>太字</bold>通常"使用例
bash
# ニュース一覧を取得
curl -H "X-API-Key: your_api_key" \
https://your-domain/api/v1/news
# カテゴリでフィルタ(5件取得)
curl -H "X-API-Key: your_api_key" \
"https://your-domain/api/v1/news?filters=category[equals]cat_123&limit=5"
# ページネーション(11件目から10件取得)
curl -H "X-API-Key: your_api_key" \
"https://your-domain/api/v1/blog?limit=10&offset=10"コンテンツ詳細の取得
特定のコンテンツを取得します。
リクエスト
GET /api/v1/{endpoint}/{contentId}パスパラメータ
| パラメータ | 型 | 説明 |
|---|---|---|
endpoint | string | エンドポイントのパス名 |
contentId | string | コンテンツID |
レスポンス
json
{
"id": "I-ChEjtNOf",
"endpoint_id": "news",
"title": "お知らせタイトル",
"data": {
"blocks": [
{
"id": "block1",
"type": "heading",
"content": "見出し",
"attrs": { "level": 1 }
},
{
"id": "block2",
"type": "paragraph",
"content": "本文テキスト"
}
]
},
"category_ids": ["cat_123"],
"published_at": "2025-12-15T12:00:00Z",
"created_at": "2025-12-14T10:00:00Z",
"updated_at": "2025-12-15T12:00:00Z"
}使用例
bash
curl -H "X-API-Key: your_api_key" \
https://your-domain/api/v1/news/I-ChEjtNOfカテゴリ一覧の取得
サービスに登録されているカテゴリ一覧を取得します。
リクエスト
GET /api/v1/categoriesレスポンス
json
{
"categories": [
{
"id": "cat_123",
"name": "重要",
"created_at": "2025-12-07T10:00:00Z",
"updated_at": "2025-12-07T10:00:00Z"
},
{
"id": "cat_456",
"name": "新着",
"created_at": "2025-12-07T10:00:00Z",
"updated_at": "2025-12-07T10:00:00Z"
}
]
}使用例
bash
curl -H "X-API-Key: your_api_key" \
https://your-domain/api/v1/categoriesエラーレスポンス
エラー時は以下の形式でレスポンスが返されます。
json
{
"error": {
"code": "NOT_FOUND",
"message": "Content not found"
}
}エラーコード一覧
| HTTPステータス | コード | 説明 |
|---|---|---|
| 400 | BAD_REQUEST | リクエストパラメータが不正 |
| 401 | UNAUTHORIZED | APIキーが無効または未指定 |
| 403 | FORBIDDEN | アクセス権限がない |
| 404 | NOT_FOUND | リソースが見つからない |
| 500 | INTERNAL_ERROR | サーバー内部エラー |
SDKとサンプルコード
サンプル実装
client-sample/ ディレクトリに、すぐに動かせるサンプル実装があります。
- index.html - ブラウザ用サンプル(一覧・詳細表示UI付き)
- api.js - 再利用可能なAPIクライアントクラス
- example-node.mjs - Node.js用サンプル
bash
# ブラウザで試す
cd client-sample && npx serve .
# http://localhost:3000 で開く
# Node.jsで試す
API_KEY=your-api-key ENDPOINT=news node example-node.mjsJavaScript / TypeScript
typescript
// fetchを使った例
async function getContents(apiKey: string, endpoint: string) {
const response = await fetch(`https://your-domain/api/v1/${endpoint}`, {
headers: {
'X-API-Key': apiKey,
},
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
return response.json();
}
// 使用例
const { contents } = await getContents('your_api_key', 'news');
contents.forEach(content => {
console.log(content.title);
});Next.js での使用例
typescript
// app/news/page.tsx
async function getNews() {
const res = await fetch('https://your-domain/api/v1/news', {
headers: {
'X-API-Key': process.env.CMS_API_KEY!,
},
next: { revalidate: 60 }, // 60秒キャッシュ
});
if (!res.ok) throw new Error('Failed to fetch');
return res.json();
}
export default async function NewsPage() {
const { contents } = await getNews();
return (
<ul>
{contents.map((item) => (
<li key={item.id}>{item.title}</li>
))}
</ul>
);
}環境変数の設定
APIキーは環境変数で管理することを推奨します。
bash
# .env.local
CMS_API_KEY=your_api_key_hereセキュリティ注意
APIキーをクライアントサイドのJavaScriptに直接埋め込まないでください。サーバーサイドで使用するか、BFF(Backend for Frontend)経由でアクセスしてください。