>> Hello there. My name is Mark,
and I'm a PM on the Microsoft Graph team.
In this video, I'll share five tips and
tricks for querying Microsoft Graph.
You may know this already,
but Microsoft Graph is the API for Microsoft.
Whether you want to provision users
in Azure Active Directory,
retrieve or send emails from Exchange,
upload files to OneDrive,
or open a web page on your phone with Device Relay,
Microsoft Graph has all the data and
functionality you need in one API.
With one app, you can easily
authenticate users with their work or personal account.
With one authentication key,
and one set of docs,
you can access user or corporate data
from most of Microsoft's cloud products.
But here's the best part.
You don't even need an app
authentication key to get started.
My first tip is to use Graph Explorer to get started.
Graph Explorer is available from our Developer Portal at
Graph.microsoft.com. Let's see it live.
Graph Explorer is a customized HTTP request tool
that makes it really easy to
discover and execute queries.
Along the left now is a series of categorized requests
and you can click on "Show more samples"
to add or remove categories.
In the main window, you
compose your request and view the response.
When you type in the URL bar,
Graph Explorer will suggest
some query options for you to choose.
But really, you can issue any query
against Graph Explorer even
if the auto completion doesn't suggest it.
Note that if you haven't explicitly logged in,
Graph Explorer is logged in with
a demo account and will not allow data modification.
Fortunately, Graph Explorer supports
logging in with a work or personal account,
at which point you can modify data.
But remember, this is the real deal.
Whatever you do through the API is actually happening.
My third tip is to learn about
the seven basic operations you can do with
Graph data and the HTTP methods required to use them.
The seven basic operations are list, get,
create, update, delete, invoke, and batch.
You can list a collection
by using "get" on the collection URL,
or you can get a single item by using "get"
on a collection URL suffixed with an ID.
For instance, "get users"
returns a list of all the users in the domain.
But "get users ID" returns just a single user.
To create new items,
post the new item to the collection URL.
In this case, we're creating a new email message
with the subject "Test."
To modify items, you typically patch,
to the resource URL.
So now, we'll modify this email so that
this subject is not "Test" but "Hello Build 2018."
So we'll change to
"Patch,"
"Hello Build 2018."
Sending delete to our resource URL
will delete the resource.
If the resource has an associated recycle bin,
like uses in groups or files,
the resource will be moved
there rather than permanently deleted.
Sometimes, operations are required
that don't map to standard crud.
For instance, there's not
a clear HTTP method for verifying a domain.
These operations also require special parameters,
so they can typically be invoked with "Post," and
the parameters can be put in the body or in the URL.
Last but not least,
if you have multiple requests
you want execute simultaneously,
you can batch them together by sending
a post to the special batch endpoint.
My fourth tip is to pay
attention to server side pagination.
We talked earlier about sending
pagination parameters with the request,
but you should also be aware that the server will apply
pagination by default to
reduce the number of records returned.
Many of the collections in Graph are already paginated
and other collections will be
paginated as they grow larger.
You should always be prepared
for a collection to be paginated.
When the server breaks results into pages,
it puts an odata.nextlink URL into each page of results.
This URL is considered opaque,
so you shouldn't try to modify it,
but it can be used to fetch the next page of results.
If there is no next link,
you are on the final page of results.
My fifth and final tip is to investigate
whether Web Hooks and
Deltas are helpful for your scenarios.
Web Hooks and Deltas those are
two tools to make some query patterns more efficient.
Web Hooks allow you to register a URL with
Microsoft Graph and configure a notification.
You can watch for ads, updates,
or deletes on a variety of resource types,
like users and email.
When a change happens,
Microsoft Graph will send
a message to the URL you registered.
This helps to avoid the need to query
Microsoft Graph at regular intervals looking for changes.
Deltas allow you to request
just the changes to a collection of resources.
Each of these tools helps you
avoid the, "Are we there yet?"
anti-pattern. When used together,
these tools are even more powerful.
When Microsoft Graph pokes you with
a Web Hook notification that something is changed,
your app can pull down just the changes using Delta.
Today, we've learned five tips
and tricks for querying Microsoft Graph.
First, Graph Explorer should be your best friend.
You can get started in seconds,
and it's a steady companion
throughout your development process.
Second, it's worth investing
some time to learn about the query parameters.
Whenever filtering is available in Microsoft Graph,
it always uses the same syntax.
Third, it's worth understanding
the seven basic operations
that Microsoft Graph exposes and how they map to HTTP.
Fourth, always be prepared for
collections to be paginated by the server.
Fifth, look to Web Hooks and
Deltas to avoid the "Are we there yet?"
anti-pattern. This is just the beginning.
For all the details about Microsoft's Graph,
start at our Developer Portal, graph.microsoft.com.
To play with Graph Explorer,
click on the link for Graph Explorer in
the top nav or use the short link, aka.ms/ge.
You can also tweet using #MicrosoftGraph or contribute to
the community samples at aka.ms/GraphCommunitySamples.
We can't wait to hear about what you build.
Thank you and happy coding.