3

When trying to access the SharePoint search service via REST, I always get an internal server error with no information about the cause of the problem.

My SharePoint app uses app-only permissions, and includes search permissions as follows:

  <AppPermissionRequests AllowAppOnlyPolicy="true">
    <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="Write" />
    <AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="Read" />
    <AppPermissionRequest Scope="http://sharepoint/search" Right="QueryAsUserIgnoreAppPrincipal" />
  </AppPermissionRequests>

I see the search permission listed when installing the app.

I know I'm getting a valid bearer token, because all of my other requests work fine. Here is the request I'm making that returns the error:

REQUEST:

$ curl -H "Authorization:Bearer abcABC...f1-iYrm-efhQ" https://<domain-my>.sharepoint.com/_api/search/query

where is the SharePoint site that I'm accessing. I've also tried this request with all combinations of headers, including Accept, Content-Type, odata, and even including the request digest. I've also tried adding query parameters, and using POST with the query in the message body. However, this is always the response I receive:

RESPONSE:

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-1, Microsoft.Office.Server.Search.REST.SearchServiceException</m:code><m:message xml:lang="en-US">An unknown error occurred.</m:message></m:error>

If I log in to SharePoint I can make a get request to /_api/search/query and it returns a non-error response. What is causing the problem with my REST request? Is there any way to get more information from the server? This is SharePoint online, so I don't have access to the server.

Thanks!

  • 1
    How did you get the farm ID? How did you make it work for Sharepoint Online? Any suggestions? – Syed Mauze Rehan Aug 3 '15 at 18:25
0

By default, if you try to call the SharePoint 2013 Search REST API as an anonymous user, you will get this error.

To enable the SharePoint 2013 Search REST API for anonymous users, first, in the Root Web of your Site Collection, create a Document Library called QueryPropertiesTemplate.

Next, create a new file called queryparametertemplate.xml based on the Properties of http://msdn.microsoft.com/en-us/library/microsoft.office.server.search.query.queryproperties_properties.aspx

Source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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