System Information
- Strapi Version:
- Operating System:
- Database:
- Node Version:
- NPM Version:
- Yarn Version:
When getting records using the entity service API by doing something like
const data = await strapi.entityService.findMany('api::book.book', {
where: {
id: 1
},
});
each entry is displayed as a hash containing the “id” field alongside the attributes at the same level of the hash, like here:
{
"id": 1,
"name": "Book name",
"website": "example.com",
"facebook_page_username": "examplepage",
"slug": "book-page",
"description": "book description",
"createdAt": "2024-01-03T17:01:26.137Z",
"updatedAt": "2024-01-03T20:51:05.045Z",
"publishedAt": "2024-01-03T17:01:29.730Z"
}
However, when querying this same record using the REST api by calling an endpoint like http://localhost:1337/api/books/1
, we get for each enty a hash with 2 keys, “id” and “attributes” following this pattern:
{
"id": 1,
"attributes": {
"name": "Book name",
"website": "example.com",
"facebook_page_username": "examplepage",
"slug": "book-page",
"description": "book description",
"createdAt": "2024-01-03T17:01:26.137Z",
"updatedAt": "2024-01-03T20:51:05.045Z",
"publishedAt": "2024-01-03T17:01:29.730Z"
}
}
This also applies to each element populated. For instance, if I populate an entry like “images”, I would get the images as an array of hashes where each hash has “attributes” and “id” keys in the second case but where attributes and the id would be all at the same level for the first case.
I am initially using the REST API but I had to add some custom routes where I am using the entity service API to retrieve data, my code is expecting hashes of “id” and “attributes” keys.
Ideally, I would like to have my api calls to the default rest routes as well as my calls to my added routes using custom controller return entries in the same pattern. Is this possible?