Jakub Tománek
Jakub Tománek

Reputation: 103

Single quote escaping in Microsoft Graph

I'm trying to query users by displayName, but I have trouble escaping single quote when sending the request by both C# SDK and Graph Explorer.

Update: It's not clear in the example, the search term I have trouble with is I'

Example query: https://graph.microsoft.com/v1.0/users?$filter=startsWith(displayName,'I%27') results in

Status Code: 400
{
    "error": {
        "code": "BadRequest",
        "message": "There is an unterminated string literal at position 28 in 'startsWith(displayName,'I'')'.",
        // snip
    }
}

I tried all sorts of escaping, with backslashes, double quotes, %2527 instead of the quote, nothing works. What's the proper way to query with a quote?

Upvotes: 10

Views: 9237

Answers (1)

Marek Rycharski
Marek Rycharski

Reputation: 1704

https://graph.microsoft.com/v1.0/users?$filter=startsWith(displayName,'I''') 

Based on http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/abnf/odata-abnf-construction-rules.txt:

SQUOTE-in-string = SQUOTE SQUOTE ; two consecutive single quotes represent one within a string literal

Upvotes: 16

Related Questions