How to filter API request by many-to-many field?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tim
    Junior Member
    • Aug 2024
    • 18

    How to filter API request by many-to-many field?

    I have 2 custom entities:

    - CCourse
    - CLecturers (don't mind plural)

    They are connected as many-to-many.

    Querying for `/api/v1/CLecturers` give me all lecturers. However if I do `/api/v1/CLecturers?where[0][type]=equals&where[0][attribute]=cCourseId&where[0][value]=81cd2999-c163-4cfd-b8ed-3eb83e04594c` Im' getting:

    > WARNING: (400) Not existing attribute 'cCourseId' in where. :: GET /CLecturers ::

    If I do `/api/v1/CLecturers?where[0][type]=equals&where[0][attribute]=courseId&where[0][value]=81cd2999-c163-4cfd-b8ed-3eb83e04594c` I get:

    > WARNING: (400) Not existing attribute 'courseId' in where. :: GET /CLecturers ::

    What am I doing wrong?
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    For an example, you can check how the frontend performs a search by many-to-many field.

    Note that this is from v9.0, whereGroup => where, attributesSelect => select for previous versions. We introduces aliases for some GET parameters to prevent false positive firewalls checks.

    Click image for larger version  Name:	image.png Views:	0 Size:	57.0 KB ID:	113268


    In docs: https://docs.espocrm.com/development...-notlinkedwith

    I recommend to use a JSON to pass search parameters. It's more convenient.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • tim
      Junior Member
      • Aug 2024
      • 18

      #3
      Thanks a lot!

      Comment

      Working...