9

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?

  • We won't be able to run your example since we lack the access token. But try mixing quotes instead of escaping: `filter=startsWith(displayName,"I'")` – MarkHu Jan 05 '17 at 17:50
  • I don't think this works: Syntax error: character '\"' is not valid at position 23 in 'startsWith(displayName,\"I'\")'. – Jakub Tománek Jan 06 '17 at 09:21

1 Answers1

15
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

Marek Rycharski
  • 1,614
  • 11
  • 10