msgraph-sdk-dotnet
msgraph-sdk-dotnet copied to clipboard
Follow site and Unfollow site missing in SDK
I am using the newest Microsoft.Graph-Package (Version: 3.32.0); in a .NET Core 3.1 Project.
Expected behavior
According to Follow Site and Unfollow Site it should be possible to follow and unfollow Sites with the help of the Microsoft.Graph SDK.
The following command should work: await graphClient.Users[$"{userid}"].FollowedSites.Add(value).Request().PostAsync();
Actual behavior
This is not possible, because the Add-Method (and also the Remove-Method) is not available. I only get the Error: "IUserFollowedSitesCollectionWithReferencesRequestBuilder" enthält keine Definition für "Add", und es konnte keine zugängliche Add-Erweiterungsmethode gefunden werden, die ein erstes Argument vom Typ "IUserFollowedSitesCollectionWithReferencesRequestBuilder" akzeptiert (möglicherweise fehlt eine using-Direktive oder ein Assemblyverweis).
Translated to: "IUserFollowedSitesCollectionWithReferencesRequestBuilder" does not contain a definition for "Add" and no extension method found...
Steps to reproduce the behavior
- Create new .NET Core 3.1 Console Project
- Install Microsoft.Graph (3.32) Package via NuGet Package Manager.
- Insert following code:
private static async Task TestFollowSite(string userid) {
GraphServiceClient graphClient = new GraphServiceClient(null);
var value = new List<Site>() {
new Site {
![followSiteError](https://user-images.githubusercontent.com/64791780/118690014-ec14cc80-b807-11eb-90a5-2ab7c5b8be17.PNG)
Id = "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740"}
};
var result = await graphClient.Users[$"{userid}"].FollowedSites.Add(value).Request().PostAsync();
}
Code to reproduce the Error:
private static async Task TestFollowSite(string userid)
{
GraphServiceClient graphClient = new GraphServiceClient(null);
var value = new List<Site>()
{
new Site
{
Id = "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740"
}
};
var result = await graphClient.Users[$"{userid}"].FollowedSites.Add(value).Request().PostAsync();
}
Somehow the attached file got inserted in this code.
This is related to https://github.com/microsoftgraph/MSGraph-SDK-Code-Generator/issues/250
This is strange scenario. Typically, references are added with a POST to the collection per OData, not using a Action. Same with using a DELETE on the collection/id/$ref.
We should add an extension method to support this scenario.
The new code generator Kiota solves it for us.
The next version of the .NET SDK will be generated through Kiota. Keeping this open until the next version is available.
Available request builder for dotnet can be found here
This is still dependent on resolution of https://github.com/microsoft/OpenAPI.NET.OData/issues/232 that will add the needed paths to the openAPI reference metadata.
For those who are still struggling with this (since the v5 did not make it better), a working workaround:
string url = "https://graph.microsoft.com/v1.0/me/followedSites";
url += add ? "/add" : "/remove";
string body = "{\"value\":[{\"id\":\"" + siteId + "\"}]}";
var request = new RequestInformation
{
HttpMethod = Method.POST,
URI = new Uri(url),
Content = new MemoryStream(Encoding.UTF8.GetBytes(body)),
};
request.Headers.Add("content-type", "application/json");
await graphClient.RequestAdapter.SendNoContentAsync(request, cancellationToken: token);
Manually setting the content-type header prevents 415 responses from graph server.