pnp / pnpcore

The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
https://aka.ms/pnp/coresdk/docs
MIT License
308 stars 193 forks source link

Bug when creating a new group connected site collection? #1567

Open LarsThomasNilsson opened 2 weeks ago

LarsThomasNilsson commented 2 weeks ago

Category

Error when creating new Sharepoint group enabled site collection (first issue reported, hope I did everything right)

Steps to reproduce

When running the follwong code I get a graph exception, "{HttpResponseCode: 400Code: Request_BadRequestMessage: The value of 'odata.bind' property annotation is an empty array. The 'odata.bind' property annotation must have a non-empty array as its value.ClientRequestId

Code: using (var pnpContext = await contextFactory.CreateAsync("SiteToWorkWith")) { var teamSiteToCreate = new TeamSiteOptions("mynewsite", "My new site") { Description = "My site description", Visibility = PnP.Core.Model.Security.GroupVisibility.Public, Owners = new string[] { "xxxx@xxxx.onmicrosoft.com" } };

     SiteCreationOptions siteCreationOptions = new SiteCreationOptions()
     {
         UsingApplicationPermissions = true
     };
     using (var newSiteContext = await pnpContext.GetSiteCollectionManager().CreateSiteCollectionAsync(teamSiteToCreate, siteCreationOptions))
     {
         // Do work on the created site collection via the newSiteContext
     };

}

Expected behavior

A new group connected site collection to be created

Environment details (development & target environment)

SDK version**: 1.14

Additional context

My Entra ID app has application permssions on Microsoft.Graph Group.Create Group.ReadWrite.All Sites.Fullcontrol.All

My Entra ID app has application permssions on SharePoint: Sites.Fullcontrol.All

It works to create a non group enabled site collection: var teamsite = new TeamSiteWithoutGroupOptions(new Uri(siteUrl), title.ToString()) { Description = description.ToString(), Language = PnP.Core.Admin.Model.SharePoint.Language.Swedish, Owner = owner.ToString(), Title = title.ToString(), SensitivityLabelId = new Guid(azureFunctionSettings.SensitivityLabelIdSite) };

//Get the context to the new site and perform additional config using (var newSiteContext = await pnpContext.GetSiteCollectionManager().CreateSiteCollectionAsync(teamsiteBDO)) {

};

Thanks for all contributions to this SDK! It's great. Sharing is caring.

jansenbe commented 19 hours ago

@LarsThomasNilsson : I just tried to reproduce your issue by running on our test cases (https://github.com/pnp/pnpcore/blob/dev/src/sdk/PnP.Core.Admin.Test/SharePoint/SiteCreationTests.cs#L940-L1036) and this worked fine using app-only permissions. Can you check that code and verify yours, if you still get an error please post the they payload you're sending to the server