REST API リファレンス
REST API では、コンテンツタイプ を API エンドポイント経由で操作できます。Strapi はコンテンツタイプを作成するときに API エンドポイント を自動生成します。クエリ時には API パラメータ で結果を絞り込めます。
このドキュメントはコンテンツタイプ向けの REST API リファレンスです。用途別の手順は ガイド も参照してください。
コンテンツタイプは既定では非公開です。公開するか、適切な権限で認証したクエリが必要です。詳しくは クイックスタート、Users & Permissions、API トークン を参照してください。
既定では REST API のレスポンスにはトップレベルのフィールドのみが含まれ、リレーション、メディア、コンポーネント、ダイナミックゾーンはポピュレートされません。特定のフィールドをポピュレートするには populate パラメータ を使います。ポピュレートするリレーションのフィールドには find 権限が付与されている必要があります。
Strapi Client ライブラリはバックエンドとのやり取りを簡素化し、コンテンツの取得・作成・更新・削除が行えます。
エンドポイント
各コンテンツタイプに対して、次のエンドポイントが自動生成されます。
複数形 API ID と単数形 API ID:
次の表では次のとおりです。
:singularApiIdはコンテンツタイプの「API ID(単数形)」の値、:pluralApiIdは「API ID(複数形)」の値を指します。
これらは Content-Type Builder でコンテンツタイプを作成するときに定義され、管理画面で編集するときにも確認できます(ユーザーガイド 参照)。例として、既定の「Article」コンテンツタイプでは次のとおりです。
:singularApiIdはarticle:pluralApiIdはarticles


- コレクションタイプ
- シングルタイプ
| メソッド | URL | 説明 |
|---|---|---|
GET | /api/:pluralApiId | ドキュメント一覧を取得 |
POST | /api/:pluralApiId | ドキュメントを作成 |
GET | /api/:pluralApiId/:documentId | ドキュメントを取得 |
PUT | /api/:pluralApiId/:documentId | ドキュメントを更新 |
DELETE | /api/:pluralApiId/:documentId | ドキュメントを削除 |
| メソッド | URL | 説明 |
|---|---|---|
GET | /api/:singularApiId | ドキュメントを取得 |
PUT | /api/:singularApiId | ドキュメントを更新/作成 |
DELETE | /api/:singularApiId | ドキュメントを削除 |
エンドポイントの具体例:
次の例は FoodAdvisor サンプルアプリからのものです。
- コレクションタイプ
- シングルタイプ
Restaurant コンテンツタイプ
| メソッド | URL | 説明 |
|---|---|---|
| GET | /api/restaurants | レストラン一覧を取得 |
| POST | /api/restaurants | レストランを作成 |
| GET | /api/restaurants/:documentId | 特定のレストランを取得 |
| DELETE | /api/restaurants/:documentId | レストランを削除 |
| PUT | /api/restaurants/:documentId | レストランを更新 |
Homepage コンテンツタイプ
| メソッド | URL | 説明 |
|---|---|---|
| GET | /api/homepage | ホームページのコンテンツを取得 |
| PUT | /api/homepage | ホームページのコンテンツを更新/作成 |
| DELETE | /api/homepage | ホームページのコンテンツを削除 |
メディアライブラリ を支える Upload パッケージは、専用の /api/upload エンドポイント があります。
コンポーネント には API エンドポイントはありません。
リクエストとレスポンス
Strapi 5 の Content API は Strapi v4 と比べて主に次の 2 点が異なります。
- レスポンス形式がフラット化され、属性は
data.attributesにネストされず、dataの直下にあります(例: 「title」はdata.title)。 - Strapi 5 では ドキュメント を使い、ドキュメントは
documentIdで参照します(破壊的変更 参照)。
リクエストのレスポンスはオブジェクトで、通常は次のキーを含みます。
-
data: レスポンス本体。次のいずれかになります。- 単一ドキュメント(オブジェクト)。キーは次のとおり。
id(整数)documentId(文字列)。特定のドキュメントをクエリするときに使う一意の識別子。- 各属性(型は属性ご とに異なります。モデルの属性 を参照)
meta(オブジェクト)
- ドキュメントの配列
- カスタムレスポンス
- 単一ドキュメント(オブジェクト)。キーは次のとおり。
-
meta(オブジェクト): ページネーション、公開状態、利用可能なロケールなどの情報 -
error(オブジェクト、任意): リクエストで発生した エラー の情報
一部のプラグイン(Users & Permissions や Upload など)はこのレスポンス形式に従わない場合があります。
ドキュメント一覧を取得
クエリのフィルターに一致するドキュメントを返します(API パラメータ 参照)。
Strapi 5 ではレスポンスがフラット化され、属性は data.attributes ではなく data 直下にあります。
Strapi 5 への移行中は任意のヘッダーを付けられます(関連する破壊的変更 参照)。
GET http://localhost:1337/api/restaurants
{
"data": [
{
"id": 2,
"documentId": "hgv1vny5cebq2l3czil1rpb3",
"Name": "BMK Paris Bamako",
"Description": null,
"createdAt": "2024-03-06T13:42:05.098Z",
"updatedAt": "2024-03-06T13:42:05.098Z",
"publishedAt": "2024-03-06T13:42:05.103Z",
"locale": "en"
},
{
"id": 4,
"documentId": "znrlzntu9ei5onjvwfaalu2v",
"Name": "Biscotte Restaurant",
"Description": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers."
}
]
}
],
"createdAt": "2024-03-06T13:43:30.172Z",
"updatedAt": "2024-03-06T13:43:30.172Z",
"publishedAt": "2024-03-06T13:43:30.175Z",
"locale": "en"
}
],
"meta": {
"pagination": {
"page": 1,
"pageSize": 25,
"pageCount": 1,
"total": 2
}
}
}
ドキュメントを 1 件取得
documentId でドキュメントを返します。
Strapi 5 では特定のドキュメントは documentId で参照します。
GET http://localhost:1337/api/restaurants/znrlzntu9ei5onjvwfaalu2v
{
"data": {
"id": 6,
"documentId": "znrlzntu9ei5onjvwfaalu2v",
"Name": "Biscotte Restaurant",
"Description": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine bassics, such as 4 Formaggi or Calzone, and our original creations such as Do Luigi or Nduja."
}
]
}
],
"createdAt": "2024-02-27T10:19:04.953Z",
"updatedAt": "2024-03-05T15:52:05.591Z",
"publishedAt": "2024-03-05T15:52:05.600Z",
"locale": "en"
},
"meta": {}
}
ドキュメントを作成
ドキュメントを作成し、その内容を返します。
Internationalization (i18n) プラグイン が有効な場合、REST API の POST で ローカライズされたドキュメントを作成 できます。
作成時にリレーションとその順序を指定できます(詳しくは REST API でのリレーション管理 を参照)。
POST http://localhost:1337/api/restaurants
{
"data": {
"Name": "Restaurant D",
"Description": [ // uses the "Rich text (blocks)" field type
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "A very short description goes here."
}
]
}
]
}
}
{
"data": {
"documentId": "bw64dnu97i56nq85106yt4du",
"Name": "Restaurant D",
"Description": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "A very short description goes here."
}
]
}
],
"createdAt": "2024-03-05T16:44:47.689Z",
"updatedAt": "2024-03-05T16:44:47.689Z",
"publishedAt": "2024-03-05T16:44:47.687Z",
"locale": "en"
},
"meta": {}
}
ドキュメントを更新
ドキュメントを部分更新し、結果を返します。
フィールドをクリアするには null を送ります。
- Internationalization (i18n) プラグイン が有効でも、現時点ではドキュメントの ロケールの更新 はできません。
- 更新時にもリレーションとその順序を指定できます(詳しくは REST API でのリレーション管理 を参照)。
PUT http://localhost:1337/api/restaurants/hgv1vny5cebq2l3czil1rpb3
{
"data": {
"Name": "BMK Paris Bamako", // we didn't change this field but still need to include it
"Description": [ // uses the "Rich text (blocks)" field type
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "A very short description goes here."
}
]
}
]
}
}
{
"data": {
"id": 9,
"documentId": "hgv1vny5cebq2l3czil1rpb3",
"Name": "BMK Paris Bamako",
"Description": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"text": "A very short description goes here."
}
]
}
],
"createdAt": "2024-03-06T13:42:05.098Z",
"updatedAt": "2024-03-06T14:16:56.883Z",
"publishedAt": "2024-03-06T14:16:56.895Z",
"locale": "en"
},
"meta": {}
}
ドキュメントを削除
ドキュメントを削除します。
成功時、DELETE は HTTP ステータス 204 の みを返し、レスポンスボディは空です。
DELETE http://localhost:1337/api/restaurants/bw64dnu97i56nq85106yt4du