Search code examples
contentful

Contentful query content type and filter on reference (multiple)


Within Contentful i have the content type "post". The post can have multiple categories (another content type). Now i'm trying to query the posts but filter them on category. My query looks something like this:

https://cdn.contentful.com/spaces/$space/entries?access_token=$token&include=3&fields.categories.fields.slug=features&limit=3&skip=0&content_type=post

The error returned: You are trying to search on a reference to an unsupported type. You can only search on references to single entries

So basically i can only reference 1 category, but i need many not only in this use case but on a lot more. Any idea how to achieve this?


Solution

  • You could flip the query around and ask for entries that link to a certain category.

    curl --include \
     --request GET \
     https://cdn.contentful.com/spaces/$SPACE_ID/environments/master/entries?access_token=$TOKEN&links_to_entry=7fYxxN67JKyUiYuE4Cq8sI&content_type=post
    

    https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/links-to-entry