Skip to content

Instantly share code, notes, and snippets.

@nth-block
Last active March 2, 2021 18:24
Show Gist options
  • Save nth-block/b4eb4b42832949b07c72d6e91f664d59 to your computer and use it in GitHub Desktop.
Save nth-block/b4eb4b42832949b07c72d6e91f664d59 to your computer and use it in GitHub Desktop.
Graph API bug while searching for users

[TOC]

Issue

Filter with startswith method

Request: Graph API query with startswith method and incorrect attribute name (userPrinicipalName - note the 'i' after 'n' in principal)

https://graph.windows.net/<tenant>.onmicrosoft.com/users?api-version=1.6&$filter=startswith(userPrinicipalName,'<username>')

HTTP Response: 400 Bad Request

{
    "odata.error": {
        "code": "Request_UnsupportedQuery",
        "message": {
            "lang": "en",
            "value": "Unsupported method 'StartsWith' in query."
        }
    }
}

Observation/Issue: Correct result but misleading error message - Unsupported method 'StartsWith' in query. whereas the error must revert an attribute not found error.
Note: This issue seemd to affect all API versions from 1.5 onwards (tried 1.5, 1.6 and beta). API version '2013-11-08' does not have this bug. See section 'Filters using old API versions'.

Expected Result

The error when the ODATA query has startswith must be the same as one when using an equality search such as below.

Filter with equality search

Request: Graph API query without a method (search for attribute directly) and the same incorrect attribute name (userPrinicipalName)

https://graph.windows.net/<tenant>.onmicrosoft.com/users?api-version=1.6&$filter=userPrinicipalName eq '<username>@<domain>'

HTTP Response: 400 Bad Request

{
    "odata.error": {
        "code": "Request_UnsupportedQuery",
        "message": {
            "lang": "en",
            "value": "Property 'userPrinicipalName' does not exist as a declared property or extension property."
        }
    }
}

Observation: Correct result and appropriate error message - Property 'userPrinicipalName' does not exist as a declared property or extension property.

Filters using old API versions

Request: Graph API query with startswith method and incorrect attribute name (userPrinicipalName - note the 'i' after 'n' in principal)

https://graph.windows.net/<tenant>.onmicrosoft.com/users?api-version=2013-11-08&$filter=startswith(userPrinicipalName,'<username>')

HTTP Response: 400 Bad Request

{
    "odata.error": {
        "code": "Request_BadRequest",
        "message": {
            "lang": "en",
            "value": "Could not find a property named 'userPrinicipalName' on type 'Microsoft.WindowsAzure.ActiveDirectory.User'."
        }
    }
}

Observation: The typo seems to give an appropriate indicator in the old versions of the API and this behaviour seems to have flipped in the later versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment