Microsoft
We're going to walk you through an example to demonstrate how to use open extensions.
Imagine you're building an application that is available on lots of different client platforms, such as desktop and mobile. You want to let users configure their UI experience so it’s consistent no matter which device they use to sign in to your app. This is a common requirement for most apps.
For this scenario, we're going to show you how to:
Note: This topic shows you how to add, read, update and delete open extensions on a user resource. These methods are also supported for the administrativeUnit, contact, device, event, group, group event, group post and organizaton resource types.
Simply update the example requests below using any of those resource types. The responses shown in the examples below may be truncated for brevity.
The user signs in to the app and configures the look and feel of the app. These app settings should roam so that the user gets the same experience on whatever device they sign in to the app from. Here we'll see how to add the roaming profile information to a user resource.
POST https://graph.microsoft.com/v1.0/me/extensions
Content-type: application/json
{
"@odata.type":"microsoft.graph.openTypeExtension",
"extensionName":"com.contoso.roamingSettings",
"theme":"dark",
"color":"purple",
"lang":"Japanese"
}
HTTP/1.1 201 Created
Content-Type: application/json
Content-length: 420
{
"@odata.type": "#microsoft.graph.openTypeExtension",
"extensionName": "com.contoso.roamingSettings",
"id": "com.contoso.roamingSettings",
"theme": "dark",
"color": "purple",
"lang": "Japanese"
}
When the user signs in to the app from another device, the app can retrieve the user's profile details as well as their roaming settings. This can be done by getting the user's resource and expanding the extension navigation property.
GET https://graph.microsoft.com/v1.0/me?$select=id,displayName,mail,mobilePhone&$expand=extensions
HTTP/1.1 200 OK
Content-Type: application/json
Content-length: 420
{
"id": "84b80893-8749-40a3-97b7-68513b600544",
"displayName": "John Smith",
"mail": "[email protected]",
"mobilePhone": "1-555-6589",
"extensions": [
{
"@odata.type": "#microsoft.graph.openTypeExtension",
"extensionName": "com.contoso.roamingSettings",
"id": "com.contoso.roamingSettings",
"theme": "dark",
"color": "purple",
"lang": "Japanese"
}
]
}
Note: If you have multiple extensions, you can filter on the id to get the extension that you are interested in.
The user may choose to change their roaming profile information. This update can be done with a PATCH on the open extension value.
PATCH https://graph.microsoft.com/v1.0/me/extensions/com.contoso.roamingSettings
Content-type: application/json
{
"theme":"light",
"color":"yellow",
"lang":"Swahili"
}
HTTP/1.1 204 No content
The user decides that they don't want a roaming profile anymore, so they delete it. This can be done with a DELETE request on the open extension value.
DELETE https://graph.microsoft.com/v1.0/me/extensions/com.contoso.roamingSettings
HTTP/1.1 204 No content