Empty meta object when using entitiyService API

System Information
  • Strapi Version: 4.2.3
  • Operating System: Mac OS 12.4
  • Database: mysql
  • Node Version: 16.13.0
  • NPM Version: 8.1.0
  • Yarn Version: 1.22.19

I am using the strapi entityService to add more filter to my query. They are based on some user details.
Everything works as expected but unfortunately the meta object remains empty. There are no information about pagination available.

Is this the desired outcome? Is there anything missing in my controller’s code?

controller find method

async find(ctx) {
        
        const userId = ctx.state.user.id
        const { query } = ctx;

        var queryCopy = { ...query }
        queryCopy.start = query.pagination.page
        queryCopy.limit = query.pagination.pageSize
        queryCopy.filters.standort = {}
        queryCopy.filters.standort.id = {}
        queryCopy.filters.standort.id.$eq = 1;

        
        const entity = await strapi.entityService.findMany('api::fahrzeug.fahrzeug', queryCopy);
        const sanitizedEntity = await this.sanitizeOutput(entity, ctx);

        return this.transformResponse(sanitizedEntity);
    }

response

{"data":[{"id":848,"attributes":{"name":"9UKE2K5H","VIN":"IB4YNHOMY6BS3QQMG","damage":true,"createdAt":"2022-05-30T08:10:19.391Z","updatedAt":"2022-06-23T08:15:26.825Z","eigennutz":false,"nutzungsverhaeltnis":"Eltern","leasingType":"MAM","neuwagen":null,"qrcode":null,"kennzeichen":null,"kilometerstand":null}},{"id":855,"attributes":{"name":"QV1QVV5W","VIN":"Q3ZKMGOLO3J364CFB","damage":true,"createdAt":"2022-05-30T08:10:22.586Z","updatedAt":"2022-06-28T13:19:35.691Z","eigennutz":false,"nutzungsverhaeltnis":"Eltern","leasingType":"MAM","neuwagen":null,"qrcode":null,"kennzeichen":null,"kilometerstand":null}},{"id":857,"attributes":{"name":"D0BOA56W","VIN":"XXV3LOL1PX64NTM01","damage":true,"createdAt":"2022-05-30T08:10:22.990Z","updatedAt":"2022-06-23T08:15:27.103Z","eigennutz":false,"nutzungsverhaeltnis":"Geschwister","leasingType":"DW","neuwagen":null,"qrcode":null,"kennzeichen":null,"kilometerstand":null}}],"meta":{}}

How can I generate the normal api output with the included pagination object?

Thanks for your help.

Regards,
Philipps

Hello,
i encounter the same issue, did you solve this problem ?

Hello,

I had the same issue but i used findPage instead of findMany.

findPage return a pagination object and accept the same parameters as findMany.

I hope it helps :slight_smile:

findPage brings the meta data however I cannot do any pagination.
I am in urgent need of this solution.
Cant get meta data from entityService.findMany and entityService.findPage ignores start and limit properties.
help please.

1 Like

Hi,
findMany and findPage, don’t accept exactly the same parameters for pagination purpose.

  • findMany needs “start” and “limit”
  • findPage needs “page” and “pageSize”

Sample:

const { results, pagination } = await strapi.entityService.findPage(
            "api::XXXX.XXXX",
            {
              filters: {
                ...filters,
                user: userId,
              },
              page,
              pageSize,
            }
          );

So we get meta data and paginated result.

Hi,
After many try in order to figure out how It work the logic of controllers (sanitized function, transforResponse function) I’ve noticed that:

  • with findMany and the parameters “start” and “limit” I get the response filtered, but I didn’t get the meta object.
  • with findPage and the parameters “page” and “pageSize” I get the response filtered with the meta object.

p.s. Is there any documentation of findPage function?

from my understanding and I could be wrong but findPage is something used internally by strapi.For the admin interface. To me more specific it is used to show relationships. Since it is not documented it is not a stable feature and can change at any time and would not be seen as a breaking change. that is also the reason why there is no documentation about it since you are not supposed to use it. so use it at your own risk and at least write a test to check if the endpoint gives the output you expect.

1 Like

thank you for the answer :slight_smile:
I think you right, but at this point I think that entityService API has missing the meta object in the response.

Were you able to find a solution? I’m also experiencing the same problem and really need a meta object with my response.

Again like my post above said findPage will give you the metadata with the other infromation if you do that on the enterty service layer