From what I’ve found, Mendix Published OData does not support using $filter inside $expand. Instead, Mendix applies the root $filter first and then performs the $expand. You could try filtering via the association in the root filter, like this:
/v1/Accounts?$filter=UserRoles/any(r:r/Name eq 'Admin')&$expand=UserRoles
Could you try this request and see if it works on your endpoint?
Okay so I played around with the accepted answer some more, since it wasn't giving me the result I expected with other associations. This approach is great if you want to filter users that have a particular user role, but if a particular account has Admin role and User role it'll still return both those in the result set.
eg.
/v1/Accounts?$filter=UserRoles/any(r:r/Name eq 'Admin')&$expand=UserRoles
{
ID: 123,
Name: "John Doe",
...
"UserRoles": [
{
"ID": 27303072740933634,
"Name": "User",
"Description": ""
},
{ "ID": 27303072740933633,
"Name": "Admin",
"Description": ""
}
]
}
Which is great, but not quite what I want. I want the roles that do not match my query to be filtered out from the result set.
TL;DR this isn't currently supported by Mendix.
(https://docs.mendix.com/refguide10/supported-odata-operations/#filtering-by-association)