2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Strapi v4でAPIのレスポンスに一部のフィールドが含まれない場合

Posted at

Strapi のバージョン4系でREST APIから返却されたJSONに一部のフィールドが含まれない現象が起きた。その解決方法を書く。

populateを指定する

MediaタイプやRelationタイプのフィールドは明示的に指定しないとデフォルトでは含まれないとのこと。含めたい場合はpopulateで指定する。(参考

全てのフィールドを含めたい場合は以下。

https://exmaple.com/restaurants?populate=*

特定のフィールドのみを含めたい場合は以下。

https://exmaple.com/restaurants?populate=top_image,categories

上記の場合、top_imageMediaタイプ)とcategoriesRelationタイプ)を含める。デフォルトで表示されるフィールドはここで指定しなくても勝手に含まれる。

populateにはもっと複雑な指定ができるので詳しくは公式サイトを参照。

権限を確認する

Relationタイプのフィールド限定だが、関係先のテーブルの読み取り権限がないと表示されない。populateで指定しても単純に無視される。まあ忘れてただけな訳だが私はこれで結構悩んだ。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?