The ability to manage Team is a capability introduced in the 1.2.7 of @pnp/graph. Through the methods described you can add, update and delete items in Teams.
import { graph } from "@pnp/graph";
import "@pnp/graph/users"
import "@pnp/graph/teams"
const joinedTeams = await graph.users.getById('99dc1039-eb80-43b1-a09e-250d50a80b26').joinedTeams();
const myJoinedTeams = await graph.me.joinedTeams();
Using the teams.getById() you can get a specific Team.
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const team = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528')();
The first way to create a new Team and corresponding Group is to first create the group and then create the team. Follow the example in Groups to create the group and get the GroupID. Then make a call to create the team from the group.
Here we get the group via id and use createTeam
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
import "@pnp/graph/groups"
const createdTeam = await graph.groups.getById('679c8ff4-f07d-40de-b02b-60ec332472dd').createTeam({
"memberSettings": {
"allowCreateUpdateChannels": true
},
"messagingSettings": {
"allowUserEditMessages": true,
"allowUserDeleteMessages": true
},
"funSettings": {
"allowGiphy": true,
"giphyContentRating": "strict"
}});
The second way to create a new Team and corresponding Group is to do so in one call. This can be done by using the createTeam method.
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const team = {
"[email protected]": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
"displayName": "PnPJS Test Team",
"description": "PnPJS Test Team’s Description",
"members": [
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": ["owner"],
"[email protected]": "https://graph.microsoft.com/v1.0/users('{owners user id}')",
},
],
};
const createdTeam: ITeamCreateResultAsync = await graph.teams.create(team);
//To check the status of the team creation, call getOperationById for the newly created team.
const createdTeamStatus = await graph.teams.getById(createdTeam.teamId).getOperationById(createdTeam.operationId);
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const clonedTeam = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').cloneTeam(
'Cloned','description','apps,tabs,settings,channels,members','public');
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const clonedTeam = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').cloneTeam(
'Cloned','description','apps,tabs,settings,channels,members','public');
const clonedTeamStatus = await graph.teams.getById(clonedTeam.teamId).getOperationById(clonedTeam.operationId);
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const archived = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').archive();
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const archived = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').unarchive();
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const channels = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').channels();
Added in 2.11.0
Using the teams.getById() you can get a specific Team.
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const channel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').primaryChannel();
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const channel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').channels.getById('19:[email protected]')();
import { graph } from "@pnp/graph";
const newChannel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').channels.create('New Channel', 'Description');
import { graph } from "@pnp/graph";
const installedApps = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').installedApps.get();
import { graph } from "@pnp/graph";
const addedApp = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').installedApps.add('https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/12345678-9abc-def0-123456789a');
import { graph } from "@pnp/graph";
const removedApp = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').installedApps.remove();
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const tabs = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').
channels.getById('19:[email protected]').tabs();
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const tab = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').
channels.getById('19:[email protected]').tabs.getById('Id')();
import { graph } from "@pnp/graph";
import "@pnp/graph/teams"
const newTab = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').
channels.getById('19:[email protected]').tabs.add('Tab','https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/12345678-9abc-def0-123456789a',<TabsConfiguration>{});
Get the members and/or owners of a group.
See Groups