contentful / contentful-management.js

JavaScript library for Contentful's Management API (node & browser)
https://contentful.github.io/contentful-management.js
MIT License
266 stars 97 forks source link

How to filter entry.getMany? #1690

Open gabdara opened 1 year ago

gabdara commented 1 year ago

Hi, in the Contentful GraphQL API we have the Collection Filters that are very helpful to filter based on some fields.

I'm looking for a way to do the same thing with Contentful Management API. All I could find is to specify content_type, but nothing for the fields.

this.client.entry.getMany<T>({
  query: {
    content_type: contentType,
    limit,
    skip,
  },
});

Without this, I would have to fetch all the entries (which are thousands and require multiple requests) to manually filter them.

gabdara commented 1 year ago

Found the answer based on Filter API results with relational queries. I think this should be added to the package documentation because it's not easy to realize it can be used in this way.

this.client.entry.getMany<T>({
  query: {
    content_type: contentType,
    limit,
    skip,
    'fields.name': 'Universal Studios'
  },
});

But still seems limited compared with the GraphQL API where we can use _not, _lt, _gt etc.

ChazUK commented 1 year ago

It feels like this is missing in the documentation and would be great to have examples of how to use each method, rather than trying to piece it together from multiple pages of docs.

The Plain API is barely mentioned here https://contentful.github.io/contentful-management.js/contentful-management/10.30.1/ and the example of getMany doesn't include any filtering.

tony-gutierrez commented 1 year ago

Yeah, one of the first code examples calls "getEntries" yet searching for that doesn't return any results. Its almost impossible to find methods and their options.

cetchebarne commented 9 months ago

Agree with the lack of documentation but also type definition is not great to cover the gap. When using "plain" API you can do this without getting any errors in your IDE and it will bring you every single published entry:

    const entries = await managementClient.entry.getPublished({
      contentTypeId: "someContentType",
    });

The entry.create method do accept contentTypeId as first parameter which makes it even easier to confuse because of syntax similarity.