{"id":504,"date":"2017-03-08T00:00:00","date_gmt":"2017-03-08T07:00:00","guid":{"rendered":"http:\/\/officedevblogs.wpengine.com\/?p=504"},"modified":"2017-03-08T00:00:00","modified_gmt":"2017-03-08T07:00:00","slug":"adding-customer-data-to-resources-in-microsoft-graph-preview","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/adding-customer-data-to-resources-in-microsoft-graph-preview\/","title":{"rendered":"Adding custom app data to Microsoft Graph now in preview"},"content":{"rendered":"<div id=\"body-content\">\n<p>Microsoft Graph provides a single API endpoint that gives you access to rich people-centric data and insights, via a number of resources like users and messages. Frequently, developers want to associate additional custom data of their own with these resource types, requiring significant additional infrastructure &ndash; until now.<\/p>\n<p>We&#8217;re happy to announce that there&rsquo;s now a way for you to <strong>extend<\/strong> Microsoft Graph with your own data. Extensions allow you to add custom properties to Microsoft Graph resources without requiring an external data store. For example, you can store app-specific user profile data in Microsoft Graph by extending the <strong>user<\/strong> resource, instead of needing to invest in dedicated data-store infrastructure for your app. Alternatively, you might want to retain your app&rsquo;s existing user profile store and link its records to users in Microsoft Graph by adding an app-specific identifier to the<strong> user<\/strong> resource.<\/p>\n<p>Microsoft Graph offers two types of extensions:<\/p>\n<ul>\n<li><strong>Open extensions<\/strong>: A good way for developers to get started with extending resources &nbsp;with custom data.&nbsp;&nbsp;<\/li>\n<li><strong>Schema extensions<\/strong>: A more versatile mechanism for developers who care about storing typed data, making their schema discoverable and shareable, being able to filter, and in the future being able to perform input data validation and authorization.<\/li>\n<\/ul>\n<p><strong>NOTE<\/strong>: Open extensions (formerly known as Office 365 data extensions) were already available for Outlook resource types&nbsp;like <strong>message <\/strong>and <strong>event<\/strong>. We&#8217;re now adding the same capability for directory&nbsp;resource types like <strong>user<\/strong> and <strong>group<\/strong>.<\/p>\n<p>Let&#8217;s take a quick look at how you can add custom data with open and schema extensions.<\/p>\n<p><h2>Using open extensions<\/h2>\n<p>Let&#8217;s say you want to let users configure their UI experience so it&rsquo;s consistent no matter which device they use to sign in to your app. Adding roaming profile information to an existing <strong>user<\/strong> resource&nbsp;can be done with a <code>POST<\/code>.<\/p>\n<p><code>POST https:\/\/graph.microsoft.com\/beta\/me\/extensions<\/code><\/p>\n<p><code>{<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"@odata.type\":\"microsoft.graph.openTypeExtension\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"extensionName\":\"com.contoso.roamingSettings\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"theme\":\"dark\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"color\":\"purple\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"lang\":\"Japanese\"<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><p><span>When the user signs in to the app from another device, the app can retrieve the user&#8217;s profile details as well as their roaming settings: <\/span><\/p>\n<p><code>GET https:\/\/graph.microsoft.com\/beta\/me?$select=id,displayName,mail,mobilePhone&amp;$expand=extensions&nbsp;&nbsp;&nbsp;&nbsp;<\/code><\/p>\n<p><code>&nbsp;HTTP\/1.1 200 OK<\/code><\/p>\n<p><code>{<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"id\": \"84b80893-8749-40a3-97b7-68513b600544\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"displayName\": \"John Smith\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"mail\": \"john@contoso.com\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"mobilePhone\": \"1-555-6589\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"extensions\": [<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"@odata.type\": \"#microsoft.graph.openTypeExtension\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"extensionName\": \"com.contoso.roamingSettings\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"id\": \"com.contoso.roamingSettings\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"theme\": \"dark\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"color\": \"purple\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"lang\": \"Japanese\"<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; ]<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><h2>Using schema extensions<\/h2>\n<p>Schema extensions allow you to define a schema you can use to extend a resource type. First, you create your schema extension definition and then use it to extend resources with strongly-typed custom data. In this example we&#8217;ll define a training &nbsp;course extension for groups which specifies&nbsp; new properties for a course ID (<em>courseId<\/em>) and a course name (<em>courseName<\/em>).<\/p>\n<p><h3>Create the schema extension definition<\/h3>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\">POST https:\/\/graph.microsoft.com\/beta\/schemaExtensions<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\">Content-type: application\/json<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\">{<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>\"id\":\"graphlearn_courses\",<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>\"description\": \"Graph Learn training courses extensions\",<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>\"targetTypes\": [<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>\"Group\"<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>],<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>\"properties\": [<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>\"name\": \"courseId\",<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>\"type\": \"Integer\"<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>},<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>\"name\": \"courseName\",<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>\"type\": \"String\"<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>]<\/span><\/code><\/p>\n<p><code><span style=\"margin: 0px;line-height: 107%;font-family: 'Courier New';font-size: 10pt\">}<\/span><\/code><\/p>\n<p><p><span>Now we have a schema definition, we can use it to describe our training course.<\/span><\/p>\n<p><h3>Add custom data by setting schema extension values<\/h3>\n<p>We can add custom data either when creating or when updating a group. When updating an existing group, add the<em> graphlearn_courses<\/em> schema extension value to the body of the PATCH request:<\/p>\n<p><code>PATCH https:\/\/graph.microsoft.com\/beta\/groups\/dfc8016f-db97-4c47-a582-49cb8f849355<\/code><\/p>\n<p><code>Content-type: application\/json<\/code><\/p>\n<p><code>{<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \"graphlearn_courses\":{<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \"courseId\":\"123\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \"courseName\":\"New Managers\"<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p>After adding the extension to the <strong>group<\/strong>, we can get the custom data together with other group data by using a <strong>$select<\/strong> statement:<\/p>\n<p><code>GET https:\/\/graph.microsoft.com\/beta\/groups\/dfc8016f-db97-4c47-a582-49cb8f849355?$select=displayName,id,description,graphlearn_courses<\/code><\/p>\n<p><code>HTTP\/1.1 200 OK<\/code><\/p>\n<p><code>{<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"displayName\": \"New Managers March 2017\",&nbsp;<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"description\": \"New Managers training course for March 2017\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"graphlearn_courses\": {<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;\"@odata.type\": \"#microsoft.graph.ComplexExtensionValue\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \"courseId\":\"123\",<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \"courseName\":\"New Managers\"<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;}<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><h2>More information<\/h2>\n<p>Please take a look at our <a href=\"https:\/\/developer.microsoft.com\/graph\/docs\/concepts\/extensibility_overview\">Extensions overview<\/a> documentation and try it out using the updated <a href=\"https:\/\/github.com\/microsoftgraph\/uwp-csharp-snippets-rest-sample\">Microsoft Graph UWP Snippets Sample<\/a> (REST) or by using <a href=\"https:\/\/developer.microsoft.com\/graph\/graph-explorer\">Microsoft Graph Explorer<\/a>. Note that you cannot create or manage schema extension definitions through Graph Explorer &#8211; for that you&#8217;ll need to create your own application.<\/p>\n<p>Please let us know what you think and what other things you&#8217;d like to see in open and schema extensions.<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft Graph provides a single API endpoint that gives you access to rich people-centric data and insights, via a number of resources like users and messages. Frequently, developers want to<\/p>\n","protected":false},"author":69077,"featured_media":25159,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3,128,11],"tags":[22,18,35,12],"class_list":["post-504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-graph","category-microsoft-teams","category-office-add-ins","tag-azure-ad","tag-excel","tag-onedrive","tag-outlook"],"acf":[],"blog_post_summary":"<p>Microsoft Graph provides a single API endpoint that gives you access to rich people-centric data and insights, via a number of resources like users and messages. Frequently, developers want to<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/69077"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=504"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/504\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/25159"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}