I want to fetch all SharePoint Sites a user has access to using graph SDK for Java (version 6.32.0). I've obtained the access token and created a graph client (I'd like to use delegated permissions to get information user has access to).
The suggestions in Microsoft Graph docs suggest using graphClient.sites().get() however this return an empty list. Even if I try the same query in Microsoft Graph Explorer the list is empty as some comment on the Microsoft learn platform suggested this only works with Application permission type (https://learn.microsoft.com/en-us/answers/questions/1103068/how-to-get-all-sharepoint-sites-of-organization-us). I then found the following API that returns all sites available to user:
https://graph.microsoft.com/v1.0/sites?search=*
and this indeed returns all the sites. Inside the graph explorer Code snippets tab there is an SDK snippet that corresponds to the above API:
SiteCollectionResponse result = graphClient.sites().get(requestConfiguration -> {
requestConfiguration.queryParameters.search = "*";
});
which I've tried to use but I get the following ODataError:
com.microsoft.graph.models.odataerrors.ODataError: Syntax error: character '*' is not valid at position 0 in '*'.
at com.microsoft.graph.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36) ~[microsoft-graph-6.32.0.jar:na]
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:212) ~[microsoft-kiota-serialization-json-1.8.4.jar:na]
at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:704) ~[microsoft-kiota-http-okHttp-1.8.4.jar:na]
at com.microsoft.kiota.ApiExceptionBuilder.<init>(ApiExceptionBuilder.java:26) ~[microsoft-kiota-abstractions-1.8.4.jar:na]
at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:703) ~[microsoft-kiota-http-okHttp-1.8.4.jar:na]
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:307) ~[microsoft-kiota-http-okHttp-1.8.4.jar:na]
at com.microsoft.graph.sites.SitesRequestBuilder.get(SitesRequestBuilder.java:119) ~[microsoft-graph-6.32.0.jar:na]
I can't figure out what I'm missing and what would be the way to do this?