Blogger

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

    Recent items

Login

Today I'm working with a particular error: when I search items that contains the single quote character through the REST API, I receive a bad request error (400 error).


The first steps is to analyze the response from the server:

  • Request: GET http://test.lucacostante.com/_api/search/query?querytext='path:http://test.lucacostante.com/Lists/Banners/Forms/AllItems.aspx OR path:http://test.lucacostante.com/Pages/L'universo.aspx'&rowlimit=5&selectproperties='Title,Path'
  • Response: Error 400: {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression \"'path:http://test.lucacostante.com/Lists/Banners/Forms/AllItems.aspx OR path:http://test.lucacostante.com/Pages/L'universo.aspx'\" is not valid."}}}

The problem is the single quote ' character into the query that provide to create a wrong query.

I've tried to encode the URL but this not resolve my problem. The solution is simpler: I need only to add another single quote to resolve my problem ('').

  • Request: GET http://test.lucacostante.com/_api/search/query?querytext='path:http://test.lucacostante.com/Lists/Banners/Forms/AllItems.aspx OR path:http://test.lucacostante.com/Pages/L''universo.aspx'&rowlimit=5&selectproperties='Title,Path'
  • Response: HTTP/1.1 200 OK
Published in SharePoint