Search code examples
contentfulcontentful-api

Is there any way to get content type's data (dropdown data)?


I'm working on contentful to create blog posts. I have created a field named with category with dropdown data, like the below image. I have created more blogs for each categories (Ex: game has 5 blogs, Tour has 10 blogs and etc). I want to show the list of all categories with content counts, Is there any possible to get all of the categories with content count? ( I can get it by getting all blogs using this query const res = ContentfulService.getEntries({ content_type: 'blog'}) then I grouped with category, but to get the category only, I don't want to get all of the blogs.)

enter image description here

Please let me know if there is a solution. Thanks


Solution

  • I have achieved that using graphQL,

    const query = { categoryCollection { items{ linkedFrom { blogCollection { total } } name:category sys { id } } } }

    let categories = await fetch(https://graphql.contentful.com/content/v1/spaces/${spaceId}, { method: 'POST', headers: { 'Content-Type': 'application/json', // Authenticate the request Authorization: Bearer ${accessToken}, }, // send the GraphQL query body: JSON.stringify({ query }), })