Mail, Calendar, and Contacts Graph API Demonstration Andrew Davidoff Senior Software Engineer Agenda
Total Page:16
File Type:pdf, Size:1020Kb
Mail, Calendar, and Contacts Graph API Demonstration Andrew Davidoff Senior Software Engineer Agenda • Introduction to Office 365 Graph APIs • Endpoints, authentication and URLs • Sample Meeting Manager application • Sample API calls for Meetings, Contacts and Email • Demonstration of API usage with Meeting Manager application • Resources What is Microsoft Graph • Microsoft Graph exposes multiple APIs from Microsoft cloud services through a single REST API endpoint. • Using the Microsoft Graph, you can turn formerly difficult or complex queries into simple navigations. • The Microsoft Graph gives you: • A unified API endpoint for accessing aggregated data from multiple Microsoft cloud services in a single response • Seamless navigation between entities and the relationships among them • Access to intelligence and insights coming from the Microsoft cloud • All this using a single authentication token. What is accessible through Microsoft Graph • Entities: • Users, groups • Mail, messages, calendars, tasks, and notes • Files and documents • From multiple services: • Outlook, OneDrive, Azure Active Directory, Planner, OneNote and others • And more: • Relationships and team work items How to use Microsoft Graph APIs • You call resource URLs using one of operations permitted on the resource: • GET • POST • PATCH • PUT • DELETE • All Microsoft Graph API requests use the following basic URL pattern: • https://graph.microsoft.com/{version}/{resource}?[odata_query_parameters] What’s in URL? https://graph.microsoft.com/{version}/{resource}?[odata_query_parame ters] • For this URL: • {version} is the target service version, for example, v1.0 or beta • {resource} is resource segment or path, such as • users, groups, devices, organization • The alias me, which resolves to the signed-in user • The resources belonging to a user, such as me/events, me/drive or me/messages • The alias myOrganization, which resolves to the tenant of the organization signed-in user • [odata_query_parameters] represents additional OData query parameters such as $filter and $select • Summary of common requests available in the Overview • http://graph.microsoft.io/GraphDocuments/en-us/overview/overview.htm Sample Meeting Manager Application • Available on GitHub • https://github.com/OfficeDev/Interop-REST-Mail-Contacts-Calendar- Sample • Sample code for two platforms: Android and Windows (UWP) • The sample is a real working application and can be used as starting point or a set of building blocks • Both applications log requests and responses to let you examine real-life traffic • UWP application has advanced, detailed logging Sample API Calls for Meetings and Events • Calendar can be queried in two ways • Events for the given time period (does not expand meeting series) • Calendar view (with expanded meeting series) • Query meetings for a selected date GET https://graph.microsoft.com/v1.0/Me/calendarView?startDateTime={}&en dDateTime={}$orderby=start/dateTime • Get description of event instance or of event series GET https://graph.microsoft.com/v1.0/Me/events/{event_id} • Accept/decline event invitation POST https://graph.microsoft.com/v1.0/Me/events/{event_id}/accept Body={…} Sample API Calls for Address Book and Contacts • Query users from address book GET https://graph.microsoft.com/v1.0/users?$top=10 GET https://graph.microsoft.com/v1.0/users?$top=10&$filter=startswith(given Name,'a') • Query number of Contacts GET https://graph.microsoft.com/v1.0/Me/contacts/$count • Query first ten contacts GET https://graph.microsoft.com/v1.0/Me/contacts?$top=10&$skip=0&$order by=DisplayName • Get user photo GET https://graph.microsoft.com/v1.0/Me/contacts/{contact_id}/photo/$value Some API Calls for Email used in the Sample • In order to Reply To (or Forward) event message, the app first does a query for an event message that corresponds to the selected event: GET https://graph.microsoft.com/v1.0/Me/MailFolders/Inbox/messages?$filter=Subje ct eq '{subject}' and CreatedDateTime gt {event_created_datetime} • If the event message has been found, the app uses createreply, createReplyAll or createForward actions to create a draft message to be sent: POST https://graph.microsoft.com/v1.0/Me/messages/{message_id}/createreply • After user clicks Send on Email page, the app updates created message: PATCH https://graph.microsoft.com/v1.0/Me/messages/{message_id} Body = {…} • … and then sends it: POST https://graph.microsoft.com/v1.0/Me/messages/{message_id}/send Demonstration: Meeting Manager Resources • Starting points for app development: • http://dev.office.com • http://graph.microsoft.io • Summary of common requests available in the Overview • http://graph.microsoft.io/GraphDocuments/en-us/overview/overview.htm • Sample Meeting Manager application: • https://github.com/OfficeDev/Interop-REST-Mail-Contacts-Calendar- Sample • Read README.md for important details and registration details Questions or Comments? Thank You!.