1

When we are trying to perform search through SharePoint API as below:


RequestEntity<String> requestEntity = new RequestEntity<>(jsonExtendedAttrs,
                headers, HttpMethod.GET,
                this.tokenHelper.getSharepointSiteUrl("/_api/search/query?querytext='title:Document*+site:'https://esab.sharepoint.com/sites/ESABSEA/Shared%20Documents/Forms/AllItems.aspx?id=%2Fsites%2FESABSEA%2FShared%20Documents%2FManuals&viewid=7f2484b4%2D5e97%2D4e07%2D88e7%2Da054edeac530''")
);

We are getting below error:

org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request: "A potentially dangerous Request.Path value was detected from the client (?)."
    at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:101)
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:168)
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122)
    at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:819)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:777)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:660)
    at com.panxoloto.sharepoint.rest.PLGSharepointClientOnline.getFolderAndFilesByRelativeUrl(PLGSharepointClientOnline.java:401)
    at TestSharepointClient.main(TestSharepointClient.java:22)

Also while using:

_api/Web/GetFolderByServerRelativeUrl('folderRelativeUrl')?$expand=Folders,Files

we are getting the same above error.

Is somebody encountered the same error and has any solution to this. Thank you.

1 Answer 1

1

If I navigate to a folder named Manuals in the library named Documents in my SharePoint site, the URL in the browser will look something like this:

https://robwindsortest991.sharepoint.com/sites/Demo/Shared%20Documents/Forms/AllItems.aspx?id=%2Fsites%2FDemo%2FShared%20Documents%2FManuals&viewid=363bb952...

That's the URL used to view the folder, but it's not the URL used to identify the folder. The URL used to identify the folder looks like this:

https://robwindsortest991.sharepoint.com/sites/Demo/Shared%20Documents/Manuals

We can confirm this using a REST API request for the folder.

Fiddler Trace

The URL that identifies the folder is the URL for the library plus the path to the folder. In this case the path to the folder is /Manuals. If the Manuals folder had a sub-folder named Procedures, the path to it would be /Manuals/Procedures.

So changing your REST API request URL to "/_api/search/query?querytext='title:Document*+site:'https://esab.sharepoint.com/sites/ESABSEA/Shared%20Documents/Manuals' should give you the result you're looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.