跳到主要内容

Strapi 5 has a new, flattened response format for REST API calls

In Strapi 5, the REST API response format has been simplified and flattened. You can set the Strapi-Response-Format: v4 header to use the old v4 format while you convert your code to fully take into account the new Strapi 5 response format.

This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

🔌 Is this breaking change affecting plugins?Yes
🤖 Is this breaking change automatically handled by a codemod?No

Breaking change description

In Strapi v4

The Content API returns all the attributes of requested content wrapped inside an attributes parameter:

{
"data": {
// system fields
"id": 14,
"attributes": {
// user fields
"title": "Article A"
"relation": {
"data": {
"id": "2"
"name": "Category A"
}
}
}
}
"meta": {
"pagination": {
"page": 1,
"pageSize": 10
}
}
}

In Strapi 5

The Content API returns attributes of requested content without wrapping them in an attributes object, and a documentId is used instead of an id:

{
"data": {
// system fields
"documentId": "clkgylmcc000008lcdd868feh",
"locale": "en",
// user fields
"title": "Article A"
"relation": {
// system fields
"documentId": "clkgylw7d000108lc4rw1bb6s"
// user fields
"name": "Category A"
}
}
"meta": {
"pagination": {
"page": 1,
"pageSize": 10
}
}
}

Migration

Notes

To use the Strapi v4 response format, set the following header: Strapi-Response-Format: v4.

Manual procedure

Ensure your API calls take into account the new response format, or set the optional header to keep on using the Strapi v4 response format (see notes).