Pnpframework: PnP Framework - Cannot set SiteAlias when creating a team site with SiteCollection CreateAsync

Created on 27 Apr 2021  Â·  2Comments  Â·  Source: pnp/pnpframework

Hello,
I am trying to create a Modern Team site using PnP Framework.
I need to set Alias and SiteAlias properties with 2 different values.
SiteCollection.CreateAsync seems to ignore the SiteAlias Property.

 var authManager = new AuthenticationManager(_sharePointAppClientId, _certificatePath, _certificatePassword, _targetOrganizationIdentity);
            var token = GetGraphAPIAccessToken();

            using (var context = authManager.GetContext(_tenantAdminUrl))
            {
                var teamsite = new TeamSiteCollectionCreationInformation
                {
                    Alias = "groupalias",
                    SiteAlias = "sitealias", // SiteAlias of the underlying Office 365 Group, i.e. the site part of the url: https://contoso.sharepoint.com/sites/<SiteAlias>
                    Description = "this is a modern team site with Office 365 Group",
                    DisplayName = "Title modern site",
                    IsPublic = true
                };

                await SiteCollection.CreateAsync(context, teamsite, graphAccessToken: token);
            }

I expected to have this site url: https://contoso.sharepoint.com/sites/sitealias
but the result is: https://contoso.sharepoint.com/sites/groupalias

Framework
.Net Core: 3.1
.Net Core PnP.Framework: 1.4

provisioning âš™ question

Most helpful comment

@renabar Setting SiteAlias is currently not supported when using graphAccessToken or App-only authentication, this is a limitation of Graph not PnP.Framework. To use it you need to have a user authenticated context like:

var authManager = new AuthenticationManager(userName, password);

or a delegated like:

var authManager = new AuthenticationManager(delegatedClientId, userName, password);

You also don't have to get a context for tenant admin, you can use any site the user userName has access to.

All 2 comments

@renabar Setting SiteAlias is currently not supported when using graphAccessToken or App-only authentication, this is a limitation of Graph not PnP.Framework. To use it you need to have a user authenticated context like:

var authManager = new AuthenticationManager(userName, password);

or a delegated like:

var authManager = new AuthenticationManager(delegatedClientId, userName, password);

You also don't have to get a context for tenant admin, you can use any site the user userName has access to.

thanks for the answer @patrikhellgren.

Was this page helpful?
0 / 5 - 0 ratings