I'm trying to use the sharepoint online search api (/_api/search) from an application. Adding it from the Azure portal I see the search is only in the "delegated permissions" section. When I ran it in testing with the user login and approve it it works well. Since I don't want to need a user to login for this, I found this article
That made me believe it would be possible to use search as an app-only and not as a user. I followed all the steps, created the app through appregnew.aspx , I also added another permission via appinv.aspx so the permissions I asked for are the following :
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/search" Right="QueryAsUserIgnoreAppPrincipal" />
</AppPermissionRequests>
I'm testing using ADAL JAVA SDK as follows:
Future<AuthenticationResult> future = context.acquireToken(
resource, new ClientCredential(clientId,
clientSecret), null);
where resource is xxxxxx.sharepoint.com and I'm later using this token as the bearer token.
But when I'm trying to test this I get the following error:
2018-08-05 11:03:22 WARN ODataUtils:120 - Failed to get a successful response for uri [https://XXXXXX.sharepoint.com/_api/search], reason [{"error_description":"The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs."}];
Since this is sharepoint online I don't have a server and I'm not using the .NET framework so what other way do I have to debug this? or other idea what I'm doing wrong here?
Any help would be greatly appreciated.
Maybe you can use the Java to call SharePoint Search Api and show the result(But we need to spend many time to research on this, there are many uncertainties.)
The best choice for you is to use the VisualStudio to test the SharePoint Addin. Microsoft provide more support on it and you can use the ready-made template.
You can use the wide range of search-related APIs that SharePoint offers for search add-ins:
.NET client object model (CSOM) Key libs: Microsoft.SharePoint.Client.Search.dll ; Silverlight CSOM Key libs: Microsoft.SharePoint.Client.Search.Silverlight.dll ; ECMAScript (JavaScript, JScript) object model (JSOM) Key libs: SP.search.js ;
Search REST API http://server/_api/search/query
Some demo code: Client-side Object Model (CSOM) C#
JavaScript Object Model (JSOM)
REST HTTP GET request HTML
HTTP POST request HTML
Then set the permissions by VisualStudio and "Napa" Office 365 Development Tools
More information on Search add in: https://learn.microsoft.com/en-us/sharepoint/dev/general-development/search-add-ins-in-sharepoint