3

I want to search graph API users for everyone whos name does not start with some value

I tried

https://graph.microsoft.com/v1.0/users?$filter="NOT startswith(displayName,'J')"
https://graph.microsoft.com/v1.0/users?$filter=not(startswith(displayName,'J'))

But I get

Invalid filter clause

Is there any way to achieve this?


I actually need to do this in C#, where I run into the same issue - I wonder if there is a way of specifying NOT STARTSWITH using the SDK?

string filter = String.Format("startswith(displayName,'J')");
List<QueryOption> options = new List<QueryOption>
{
    new QueryOption("$filter", filter)
};
var users = await graphClient.Users
    .Request(options)
    .Top(500)
    .GetAsync();
Bassie
  • 9,529
  • 8
  • 68
  • 159

2 Answers2

2

I'm afraid this type of filter is not supported by users (or any other Azure AD resources). From the documentation:

The following $filter operators are not supported for Azure AD resources: ne, gt, ge, lt, le, and not.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
  • Thanks Marc. Do you happen to know what the performance implications would be for writing a filter which searches for users whos name `startswith` **every character except for the one I need to exclude**? E.g. `startswith(displayName,'A') OR startswith(displayName,'B') OR startswith(displayName,'C')..` etc (it would just contain each letter of the alphabet, so 26 `startswith`s – Bassie Mar 09 '18 at 16:44
  • It would seem far more performant to just pull the entire list and then filter on the client side (i.e. `Linq` against the `Users` collection). – Marc LaFleur Mar 09 '18 at 17:18
1

Its not users, but i managed to get data with not startsWith like this:

client.DeviceManagement.ManagedDevices.Request().Filter("not startsWith(operatingSystem, 'Windows')").GetAsync()

arccuks
  • 173
  • 2
  • 12