Please specify what version of the library you are using: [ 1.2.1 ]
When creating a group using the pnp.graph it should create a group and a team site in sharepoint.
Doesn't always create a team site, a couple times the code has worked but majority of the time it just creates a group without a corresponding sharepoint site.
Using the graph API creating a group then assigning a owner, this is successful but then when i check if a teamsites been created in my sharepoint tenant it hasn't created the site. But If i check the graph api the group has been created.
`
addGroup = (groupName: string, url: string) => {
return new Promise((resolve, reject) => {
graph.groups.add(groupName, url, 0).then((group: any) => {
console.log(group, "group obj");
this.groupId = group.data.id;
this.addOwner(group.data.id).then((e) => {
// console.log(e)
return resolve("Successfully created Group");
}).catch((e) => {
group.delete();
return reject(e);
})
}).catch((e) => {
return reject(e);
})
})
}
private addOwner = (groupId: string) => {
return new Promise((resolve, reject) => {
let adminId = "<ID>";
let url = `https://graph.microsoft.com/v1.0/groups/${groupId}/owners/$ref`;
let payload = {
"@odata.id": `https://graph.microsoft.com/v1.0/users/${adminId}`
}
apiManager.post(url, payload).then((e) => {
return resolve(e);
}).catch((e) => {
return reject(e);
});
})
}
`
@KieranDaviesV Are you sure that the site isn't created, that you don't forget about the "url" being the name of the site?
For instance, the first time I forgot that I named the group "Test", but the url was demo. So ofcourse I had to navigate to "sites/demo"
Anyways, I tried this code, and it worked every time I tried it.
This shouldnt be a PnPJs issue. It's internal plumming in Office365/SharePoint that creates the Team Site. Just remember that the second parameter is responsible for the URL.
Maybe have a look at fiddler to see that you get ok posts and gets!
public async addGroup(groupName: string, url: string, owner: string): Promise<void> {
const newGroup: GroupAddResult = await graph.groups.add(groupName, url, GroupType.Office365);
return (await graph.groups.getById(newGroup.data.id).owners.add(`https://graph.microsoft.com/v1.0/users/${owner}`));
}
@simonagren Yeah positive. So I just replicated your code and ran it, I received 4/5 successfully created. The fifth said it was created and the group exists but no team site in sharepoint.
@KieranDaviesV I'm sorry to hear that, it sounds really weird. How and where do you use the function?
I tried now aswell in the SPEditor chrome extension, from the console.
I did all the way from "graphtest" to "graphtest5", so 6 in total. All the SharePoints sites were created really fast for me.
import { graph, GroupAddResult, GroupType } from "@pnp/graph"
if ((window as any).moduleLoaderPromise) {
(window as any).moduleLoaderPromise.then(e => {
graph.setup({
spfxContext: e.context
})
}) }
else { console.log("to work with graph, switch to modern page!") }
(async () => {
const newGroup: GroupAddResult = await graph.groups.add('graphtest5', 'graphtest5', GroupType.Office365);
await graph.groups.getById(newGroup.data.id).owners.add(`https://graph.microsoft.com/v1.0/users/[email protected]`);
})().then(() => console.log('Yay')).catch(console.log)
@simonagren I'm running a demo tenant and I'm running the code from an azure function. It seems to be working fine when I just use the rest api, but otherwise it seems to every couple I create not create one of them.
Such a bizarre occurrence, is this more an internal issue than a library issue do you think?
@KieranDaviesV Ok!
It shouldn't be an PnPJs issue, since the group is created. The library just makes a rest call to the Graph, I could do the same without PnPJs aswell.
So after the call to the endpoint, Microsofts internal functions creates the SharePoint Site etc. And It should do that every time.
I don't now if it possibly could ahve to do with creating to many at once? Just an unqualified "thinking out loud".
Other than that, you could paste the function code here if you want and I could try later.
@simonagren I've moved away from the library and I'm just using the REST API, and I haven't had a single issue. I am also creating multiple groups at once using this method so i dont think thats it. I did at first have a suspicion that could have been the case, but now I have no clue where the issue lies.
@KieranDaviesV - sorry to hear we couldn't work together on fixing things. Understand you've found another way to accomplish your task so glad at least to hear that. Going to lose this issue, if you'd like to revisit please _reopen_ and we'll try and get you sorted. Thanks!