Add custom data to users using open extensions

This article demonstrates how to use open extensions.

Imagine you're building an application that is available on multiple 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.

For this scenario, this article will show you how to:

  1. Add an open extension representing some roaming profile information about the user.
  2. Query the user and return the roaming profile.
  3. Change the user's roaming profile information (the open extension value).
  4. Delete the user's roaming profile information.

Note

Apart from users, open extensions are also supported and can be managed for other resource types.

1. Add roaming profile information

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. The app calls Microsoft Graph by running the following request to add the roaming profile information to a user resource.

Request

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"
}

Response

HTTP/1.1 201 Created
Content-Type: application/json

{
    "@odata.type": "#microsoft.graph.openTypeExtension",
    "extensionName": "com.contoso.roamingSettings",
    "id": "com.contoso.roamingSettings",
    "theme": "dark",
    "color": "purple",
    "lang": "Japanese"
}

2. Retrieve roaming profile information

When the user signs in to the app from another device, the app calls Microsoft Graph to retrieve the user's profile details and expand the extensions navigation property to get their roaming settings.

Request

GET https://graph.microsoft.com/v1.0/me?$select=id,displayName,mail,mobilePhone&$expand=extensions

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
    "id": "84b80893-8749-40a3-97b7-68513b600544",
    "displayName": "John Smith",
    "mail": "john@contoso.com",
    "mobilePhone": "1-555-6589",
    "extensions": [
        {
            "@odata.type": "#microsoft.graph.openTypeExtension",
            "extensionName": "com.contoso.roamingSettings",
            "id": "com.contoso.roamingSettings",
            "theme": "dark",
            "color": "purple",
            "lang": "Japanese"
        }
    ]
}

3. Change roaming profile information

The user can choose to change their roaming profile information. The app calls Microsoft Graph by running the following query.

Request

PATCH https://graph.microsoft.com/v1.0/me/extensions/com.contoso.roamingSettings
Content-type: application/json

{
    "theme":"light",
    "color":"yellow",
    "lang":"Swahili"
}

Response

HTTP/1.1 204 No content

4. Delete a user's roaming profile

The user decides that they don't want a roaming profile anymore, so they delete it and the app calls Microsoft Graph by running the following request.

Request

DELETE https://graph.microsoft.com/v1.0/me/extensions/com.contoso.roamingSettings

Response

HTTP/1.1 204 No content

See also