Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to filter entry.getMany? #1690

Open
gabdara opened this issue Feb 16, 2023 · 4 comments
Open

How to filter entry.getMany? #1690

gabdara opened this issue Feb 16, 2023 · 4 comments

Comments

@gabdara
Copy link

gabdara commented Feb 16, 2023

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
Copy link
Author

gabdara commented Feb 16, 2023

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
Copy link

ChazUK commented Mar 22, 2023

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants