1

I'm trying to filter Directus CMS data set through URL parameters. This is a sample data set. I can successfully filter data set by single parameter.

{
   "data":[
      {
         "id": "1",
         "status": "published",
         "category": "Novel",
         "section": "Kids"
      },
      {
         "id": "2",
         "status": "published",
         "category": "Novel",
         "section": "Adults"
      }
   ]
}

/items/books?filter[category][_eq]=Novel

gives me exactly what I expected which is 1 & 2 data records. But I need to filter both "category" & "section" fields

/items/books?filter[category][_eq]=Novel&filter[section][_eq]=Adults 

For above I receive an empty data set. Why is this getting failed ? Where do I need to fix? Appreciate your support in advance. Thanks!

1 Answer 1

1

Try the following query:

/items/books?filter={"_or":[{"category":{"_eq": "Novel"}},{"section":{"_eq":"Adults"}}]}

An expanded version of the filter:

"_or": [
    {
        "category": {
            "_eq": "Novel"
        }
    },
    {
        "section": {
            "_eq": "Adults"
        }
    }
]

Visit the official docs to read more about filtering rules and logical operators.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.