Forum Discussion
Programmatically creation of Office 365 Groups
- Aug 25, 2017
You are one lazy.... ;)
Tenant tenant = new Tenant(clientContext);
var site = tenant.GetSitePropertiesByUrl(siteUrl, false);
clientContext.Load(site, s => s.Status);
site.Context.ExecuteQueryRetry();
var status = site.Status;
Hi folks,
So after a few months, I'm trying to this again in order to automate the process and I'm facing the same challenge. Office 365 groups creation is of course disable in the organization, otherwise people will just create a mess, so I plan to do provisioning using app-only delegated tokens. Group creates, without logo and always public (even though I specify imagare stream and private) but no site before I call the URL mentioned below..however I cannot just call the URL, it can only be called under some user. For that you need to have username/password..then site creates, at some point. You do not know when, so keep waiting and checking if site exists..when done, you can start customizing it to your company needs.
Quite a complicated process to provision group and site from C# . Is this really the only way ? It's on the edge of hacking the system. I can't believe Microsoft made it that hard for enterprise customers to work with this. Anyone has some new findings ?
Group creation with app-only works fine for me, now. The SharePoint site creation is started instantly and public/private is working as expected.
Currently, I see though an issue where the SharePoint site is in creating state for quite a while, e.g. 75 minutes.
- Tomas PaulasAug 25, 2017Brass Contributor
Then I'm really wondering how you do it :) . I digged into PnPCore in GIT
UnifiedGroupsUtility.CreateUnifiedGroup
function and App-only token will create the group, add members and that's it. When its adding logo, it returns "Message: Access is denied. Check credentials and try again." and when creating site it returns "AccessDenied Message: Either scp or roles claim need to be present in the token." In order this to work I have to request token based on users token that is calling the app. With this token I can upload the logo and set it to private/public.
I tried whatever possible, but still the same. Today I will try to delete the site, but I'm nearly sure if I delete the group as api-only perm. it will leave the site orphaned, because this is connected with the user token again. So it is the user who should do the action.
Thank you for your advice.
cc: Mikael Svenson
- Mikael SvensonAug 25, 2017Iron ContributorWe're using the New-PnPUnifiedGroup commandlet, and setting public/private works.
Logo is not supported (yet) using app only, as mentioned in the MS Graph documentation - https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues- Tomas PaulasAug 25, 2017Brass Contributor
OK, now I understand, but that is PowerShell. I'm talking c#. PowerShell is nice and powerfull tool for administration and automation of tasks, however we need to implement it in c# .NET webAPI that is offering integration with other business systems, so users can create group and site (that acts as project team site) on demand from the ERP system.
So, I will stick to use of both tokens for now and wait with hope for Microsoft's next steps. :)
Tomas
- Mikael SvensonAug 24, 2017Iron Contributor
That's what I see as well. It takes from 30+ minutes to turn Active, and you cannot really safely program against it before it's "Active" as you can get weird errors if you start too early depending on the feature. cc VesaJuvonen
- Bernd RickenbergAug 28, 2017Brass Contributor
I almost wondered whether I was the only one getting this error... Thanks :-). Today, site creation seems more stable - only about 50 % of the sites take long time to turn active. Vesa Juvonen any news on the issue you can share?
To begin with I had the same point of view - you should not work with a site that does not have the status Active. I tried with a lot of sites applying programmatic changes while in Creating state and have seen very low error rates (below 1 % of maybe 3000 sites). It saves about 2-3 minutes each time a site is created for the 99 %. In case an error occurs, a web job re-applies the programmatic changes one more time until they go through without any errors.
- Tomas PaulasAug 25, 2017Brass Contributor
Active site is the next challenge...I need to further provision the site (create some lists, add additional non-O365group members etc.) I thought the best way would be tenant-wide deployed provider hosted app with AppInstalled handler that will do the stuff needed. Another approach is wait until site is ready in the same code where we provision group and that brings me to another question :) how you check if site is "Active" in C#. I know the PowerShell command for that but did not find any for C# CSOM any hint ?
Tomas
- Mikael SvensonAug 25, 2017Iron Contributor
You are one lazy.... ;)
Tenant tenant = new Tenant(clientContext);
var site = tenant.GetSitePropertiesByUrl(siteUrl, false);
clientContext.Load(site, s => s.Status);
site.Context.ExecuteQueryRetry();
var status = site.Status;