locked
Error when searching for string containing '&' in OData filter via Web API RRS feed

  • Question

  • Hi,

    Need a solution on how to make OData query work with  $filter=Name eq 'AT&T'

    It always fails with 400 error

    Even after URL encoding, it still fails.

    $filter=Name eq ‘AT%26T’

    It seems that Web API will decode the URL and still send the & to OData URL parser and the following error is being thrown:

    "There is an unterminated string literal at position ..."

    Thanks

    Wednesday, June 4, 2014 12:24 PM

All replies

  • 40404,

    I think you are misisng a ? before the $filter. Here is the syntax, that I used, and it works.

    https://<PWA address>/_api/ProjectData/Projects/?$filter=Name eq 'AT%26T'


    Prasanna Adavi,PMP,MCTS,MCITP,MCT TWitter: @prasannaadavi Blog: http://www.prasannaadavi.com

    Wednesday, June 4, 2014 6:38 PM
  • Hi,

    Thanks for the quick answer, unfortunately the problem is not in missing '?' before the $filter.

    http://services.odata.org/OData/OData.svc/Products?$filter=Name eq 'AT&T' with any http client, you'll receive the error described below :

    There is an unterminated string literal at position 11 in 'Name eq 'AT'.

    If I try with

    http://services.odata.org/OData/OData.svc/Products?$filter=Name eq 'AT%26T', it will work but will query against '%26' literal instead of decoding it to '&' and searching against '&' symbol. So I will receive results if there is "AT%26T" and not "AT&T".

    Hope I was clear enough.

    Thanks,

    David


    Friday, June 6, 2014 9:21 AM
  • David,

    Yes you are clear enough. And I can confirm that the encoding is needed and correct, and using the syntax i men tioned above, it works fine when I test it. It does not do a literal search using AT%26T, but rather brings up values for AT&T.

    Are you trying to query a SharePoint list or Project Data?


    Prasanna Adavi,PMP,MCTS,MCITP,MCT TWitter: @prasannaadavi Blog: http://www.prasannaadavi.com

    Friday, June 6, 2014 12:38 PM