Contentful logo

Contentful Community

How do I get entries by content type?

#1

For intsance say I have a books type and then an author type…

when I use client.getEntries(); (JS) how do I search by only books?

#2

You can use the content_type parameter. Docs are here: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/content-type

#4

So where do specify the content_type URI?

is it client.getEntry(‘URI’) ?

client.getEntires(‘URI’) ?

The docs are sort of confusing :frowning:

#5

getEntry only takes a single id and returns that item while getEntries return multiple items and has many parameters to filter what you get back. If you want to get all items with the content_type id "book" items you would do something like:

client.getEntries({
  content_type: "book"
}).then(response => {
  return response.items;
});