>> Hi. Welcome to Microsoft Build. I'm Nick Kramer.
This is Microsoft Teams APIs in Microsoft Graph.
If you're not familiar with Microsoft Graph,
it's the REST endpoint that unifies
the different Microsoft properties across Office 365
and other Microsoft properties into
a single SDK and a single Developer experience,
and Microsoft Teams is the hub for
teamwork in Office 365.
It allows you to communicate using chat, meetings, calls,
to collaborate using all the office properties
including SharePoint files, and Excel,
and OneNote, and Planner, and Calendar,
and the full breadth of Office 365 integrated into Teams.
Microsoft Teams also has a rich customization experience,
so you can write apps inside of Microsoft Teams,
which we'll talk more about in a minute.
And across Teams, you get
that enterprise awareness that
you're used to from Microsoft.
Teams provides a powerful platform for building
applications including ability to build Tabs,
Bots, Connectors, Actionable Messages and Cards,
Messaging Extensions, and of course, Graph APIs.
Graph APIs can be
used with all of those other different models.
So you can have a Tab that calls
Graph APIs or a Bot that calls Graph APIs,
Connectors that call Graph APIs,
et cetera, and you can also
use those Graph APIs outside of Teams.
So, use Graph APIs in
your website to manipulate Teams data.
Use Graph APIs in your services,
or even Graph APIs in your command line tools.
One of the powerful things you can do with
those APIs is automate the life cycle of your team.
So, you can create a team and
then add members and owners to that team,
add some channels to that team,
configure the team settings,
post a welcome message to the team,
and then let your users party on that team.
And when they're done,
when the business issue
that you're tying to that team is resolved,
you can then go ahead and delete the team.
To that end, we have a bunch of APIs today to do that.
We have access to the team resource.
We let you read,
write, add, and remove an update,
and delete those, as well as enumerate
the Teams that a member has.
We have APIs for manipulating membership,
adding and removing people to the membership list,
adding and removing people to the owner list,
and also enumerating who those owners and members are,
and getting additional information about them such as,
what their full name is,
their email address, their user picture, et cetera.
Team settings is another one of
the things you can get access to,
both reading and writing the settings of a team.
Channels, we have full ability to add, read,
update, delete your channels,
as well as enumerate the channels in a team.
And you can post channel messages to those channels.
Let's show a demo illustrating that.
I'd like to show you a little application
from Contoso Airlines.
Contoso, likes to create
a new team for every flight they fly,
and put the pilots and the air crew,
and the ground crew,
and the air stewards on that flight,
and on that team.
So all the people that need to work
together are in one team, making it happen.
On their website, first thing you need to do is log in,
provide your Graph credentials
and then you get a list of flights that are flying out,
and the magic, "Create team" button.
And let's walk through what that does.
First step to creating a team is creating a group.
We're going to set up the parameters that we want here,
display name, mail nickname, description.
Those are also what are displayed for the team.
Need to specify group type as unified,
"mailEnabled" to true, "securityEnabled" is false.
You don't want a security group,
you want a Teams group.
And finally, your favorite visibility.
I used private here,
but public visibility is good if you want
people to be able to add themselves into Teams.
And then, we need to do
an HTTP call just like standard REST stuff.
I have a little helper method here called
"callGraph" that does all the standard HTTP things.
It's a thin wrapper around HTTP client.
First, we serialize the payload into JSON format.
Then we set some request headers,
set an except header,
set an authorization header,
put the body into the request,
and then actually send the request through HTTP client.
Then we process the response code.
It's a success. We move on.
And so,
the next step is going to be to put a team
into that group. We have a group.
We need to put a team in there,
and we're going to specify
a payload that has
the settings for the team we're about to create.
And when we create the group,
we got back in ID,
and that's going to be useful for our subsequent calls.
So, I could specify a blank payload and say,
"Use all the default settings."
But here, I'm going to specify
a couple settings that I want to override.
I want to override whether
guests can create and update channels,
I want to set that to false,
and I'm overriding whether guests can allow
deleted channels or allowed to delete channels as well.
And then, I'm going to use all the defaults
for all the other settings.
And when we do that, we'll have a team.
A team with no members in it, but a team.
And the next step is to go through
the flight roster and add people to that team.
So, my database has the flight crew listed
by user principle name, UPN.
Graph likes to work in object IDs.
You need to add an object ID to the member list.
So, our first step is going to be to
translate that UPN into a ID.
Fortunately, there's a Graph call for that, /users/UPN,
will give you information about that person and
then we just pick out the ID field out of that.
Then we construct the payload
that we can pass to the membership list,
OData.id equals blah blah blah /userID.
And then we call, /groups/id/members/$ref,
post to that, and that adds
the user to the membership list.
If we want to then add them as
an owner as well as a member,
we can do that as well with another call,
/groups/id/owners, instead of /members.
For performance reasons, it's best to do this
through the beta APIs right now.
We recently did a lot of performance work to make
the adding members really zippy in the Teams client.
If you use the V1 endpoints,
it will take its time showing up.
If you use the beta endpoints to add the user,
that user will show up very quickly and the Teams client.
So, seeing one user,
we've seen them all, we can skip over the rest here.
Next step is for us to create a channel.
And again, we need to put it in a couple of settings.
In this case, just the display name of the description,
and then we send that REST payload
over, and we'll have a channel.
And finally, let's put
a little welcome message into that channel.
We're going to post a message
to this URL
/group/id/team/channels/channelid/chatthreads.
And we'll put a little body for a message in there.
"Welcome to flight 210."
And when we do that,
we're going to get ourselves
a nice team that's pre-created for running your flight.
You can see flight 210
with service to Dallas has been created,
with pilots, and has a nice welcome message from us.
Now, I want to talk about, what we're
looking at next for the product.
And I wanted to get your feedback on this.
For automating team life cycles,
we're thinking about introducing
a feature for archiving Teams.
When you're creating new Teams
automatically at a rapid clip,
a new team a day,
those Teams pile up.
You can very quickly create a mess.
Now, one solution is to delete
those Teams as soon as you're done with them.
But that means, you can't go back and
lead the previous day's team.
Another possibility would be an archive concept,
where we put those Teams into
a read-only mode and hide those Teams,
make them harder to get to so
they don't clutter up your list of Teams,
but still make them accessible through a menu.
That's one feature we're looking at.
We'd like your feedback on.
Another is application permissions.
The Teams APIs and Graph today
support what's called user delegated
permissions where the application
runs with the permissions of the person logged into it.
That's great as long as you have a user logged into it.
But if you're running a service at the stroke of
midnight to look at the flights for the next day,
you may not have a user logged in.
In which case, application permissions
can be really handy.
A third scenario that we're looking at
is adding apps, and tabs,
and bots into Teams,
so providing APIs for adding
those things into the Teams you just created.
A final thing that we're looking
at is getting the ability
to read channel messages as part of
building out that messaging theme.
So, there's a couple of
great talks that I recommend for everyone at Build.
Build has a lot of great talks but two in particular.
By Andrew Bybee and Larry Djin,
Build the ultimate team hub with
Microsoft Teams will tell you
all about the Teams platform,
not just the Graph portions.
And Yina Arenas will tell you all about Microsoft Graph,
the full breadth of Graph across
all the different products that
contribute to the Graph API set.
So, get started building your Teams app today.
Go to graph.microsoft.com.
Let us know what you're doing on Twitter.
If you have feedback,
send us a tweet.
Check out the samples on GitHub.
Post your questions to StackOverflow,
and please, let us know what you think.
We'd love to hear from you. Thank you very much.