3

I can't find (even in the docs) the best way to do an API call with M2M, from sdk-js. For example, if I have two collections "articles" and "categories" with an M2M relation. How do I get all the articles from one categorie_id ?

I've tried this :

directusClient.getItems(
  'articles',
   {
     filter: {
       categories: {
         id: req.params.id
       } 
     }
   }
)

But I get this error : Error: Unknown filter: id at new APIError.

Medteck
  • 496
  • 4
  • 12

1 Answers1

4

I've found my error.. I just had to use filters instead of filter. Thus, I had to use the attribute categories_id instead of id.

Final code :

directusClient.getItems(
 'articles',
 {
   filters: {
     categories: {
       categories_id: req.params.id
     }
   }
 } 
)
Medteck
  • 496
  • 4
  • 12