Blogger

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

    Recent items

Login

Friday, 10 October 2014 14:17

Bad request (400 error) when you use REST API to search items and the querytext contains the single quote character

Written by
Rate this item
(0 votes)

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
Read 35773 times

3 comments

  • Comment Link avrahamcool Monday, 29 December 2014 15:00 posted by avrahamcool

    Great post,

    when using POST, the ' (single quot) need to be transformed to \' (backslash single quot)

    Report
  • Comment Link battlefront cheat Monday, 19 October 2015 16:55 posted by battlefront cheat

    Hi there, You have done an excellent job. I'll certainly
    digg it and personally suggest to my friends. I am sure they will be benefited from this website.

    Report
  • Comment Link Trudy Thursday, 05 October 2017 13:02 posted by Trudy

    Hello there, You've done a great job. I'll certainly digg it and personally recommend to
    my friends. I am confident they will be benefited from this website.

    Report

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.