Microsoft Graph Open Extensions

Microsoft Graph Open Extension allows to add untyped custom data to resources, like User and Messages, and there single API endpoint that gives you the possibility to extend Microsoft Graph with your own application data. You can add custom properties to Microsoft Graph resources without requiring an external data store.

Here a list of resources that are supported

ResourceVersion
Administrative unitPreview only
Calendar eventGA
Group calendar eventGA
Group conversation thread postGA
deviceGA
groupGA
messageGA
organizationGA
Personal contactGA
userGA

List of Microsoft Graph Rest API’s Available

Use Case

Here I will show you how to use open extension to add new custom data to User Resource.

Scenario

I want to give the user the possibility to manage their owns application links, for that I create SPFx web part where the user can define the name, description, Url and Icon. This applications will be rendering as grid of tiles on SharePoint Site, Teams Tab or Teams Personal App.

Here a screenshots of My Personal Apps.

User add new Application links

The links are saved in User resource instance in Extensions property.

We can see how the extension was created in User resource instance executing the followed MSGraph Rest API.

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

In the response you can see in the Extensions property the data that was saved.




{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,mail,mobilePhone,extensions())/$entity",
    "id": "33be46e1-8651-4ba3-8b43-2acbf95e71e8",
    "displayName": "João José Mendes",
    "mail": "joao.mendes@devjjm.onmicrosoft.com",
    "mobilePhone": null,
    "extensions@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('33be46e1-8651-4ba3-8b43-2acbf95e71e8')/extensions",
    "extensions": [
        {
            "@odata.type": "#microsoft.graph.openTypeExtension",
            "Apps": [
                {
                    "name": "My SAP",
                    "description": "SAP Access",
                    "Url": "https://www.sap.pt",
                    "iconName": "AppIconDefault",
                    "tableData": {
                        "id": 0
                    }
                },
                {
                    "name": "Q&A",
                    "description": "Quick Access",
                    "Url": "https://www.qa.pt",
                    "iconName": "SurveyQuestions",
                    "tableData": {
                        "id": 1
                    }
                },
                {
                    "name": "My Reports",
                    "description": "FI Reports 2",
                    "Url": "https://www.sap.pt",
                    "iconName": "CRMReport",
                    "tableData": {
                        "id": 2
                    }
                },
                {
                    "name": "My CRM",
                    "description": "CRM - Support",
                    "Url": "https://www.crm.pt",
                    "iconName": "AnalyticsView",
                    "tableData": {
                        "id": 3
                    }
                },
                {
                    "name": "Travels",
                    "description": "Travel Agencies",
                    "Url": "https://www.tap.pt",
                    "iconName": "AirplaneSolid",
                    "tableData": {
                        "id": 4
                    }
                },
                {
                    "name": "My Redmind",
                    "description": "Redmind",
                    "Url": "https://www.red.pt",
                    "iconName": "Help",
                    "tableData": {
                        "id": 5
                    }
                },
                {
                    "name": "Office 365",
                    "description": "My Office 365",
                    "Url": "https://office.com",
                    "iconName": "OfficeLogo",
                    "tableData": {
                        "id": 6
                    }
                },
                {
                    "name": "TN3270",
                    "description": "Mainframe Access",
                    "Url": "https://tn3270web/",
                    "iconName": "Database",
                    "tableData": {
                        "id": 7
                    }
                },
                {
                    "name": "My App",
                    "description": "Access to My App",
                    "Url": "https://www.google.pt",
                    "iconName": "PowerApps2Logo",
                    "tableData": {
                        "id": 8
                    }
                }
            ],
            "id": "MyApps"
        }
    ]
}

The Extensions property is an array with all of Extensions created for the resource and is derived from the extension abstract type. Each extension has an extensionName (id in the response) property which is the only pre-defined, writable property for all extensions, along with your custom data.

My Personal Applications will create an extension called “MyApps” for the User and has an attribute called “Applications”, which is a set of objects with information about the applications defined by the user..

The Extension is automatically created if not exists when the User save their list of Applications .

Create an Extension

We can create extensions when creating a new resource or for existing resources, we just have to include the value of the Extensions property in the body of the request.

In this case the Extension is created by the Application for the current user. we can access to extension of a resource using the

Sample of the request with body that is called.

POST https://graph.microsoft.com/v1.0/me/extensions
{
  "@odata.type" : "microsoft.graph.openTypeExtension",
  "extensionName" : "MyApps",
  "Apps": [
                {
                    "name": "My SAP",
                    "description": "SAP Access",
                    "Url": "https://www.sap.pt",
                    "iconName": "AppIconDefault",
                    "tableData": {
                        "id": 0
                    }
                },
                {
                    "name": "Q&A",
                    "description": "Quick Access",
                    "Url": "https://www.qa.pt",
                    "iconName": "SurveyQuestions",
                    "tableData": {
                        "id": 1
                    }
                },
                {
                    "name": "My Reports",
                    "description": "FI Reports 2",
                    "Url": "https://www.sap.pt",
                    "iconName": "CRMReport",
                    "tableData": {
                        "id": 2
                    }
                },
                {
                    "name": "My CRM",
                    "description": "CRM - Support",
                    "Url": "https://www.crm.pt",
                    "iconName": "AnalyticsView",
                    "tableData": {
                        "id": 3
                    }
                },
                {
                    "name": "Travels",
                    "description": "Travel Agencies",
                    "Url": "https://www.tap.pt",
                    "iconName": "AirplaneSolid",
                    "tableData": {
                        "id": 4
                    }
                },
                {
                    "name": "My Redmind",
                    "description": "Redmind",
                    "Url": "https://www.red.pt",
                    "iconName": "Help",
                    "tableData": {
                        "id": 5
                    }
                },
                {
                    "name": "Office 365",
                    "description": "My Office 365",
                    "Url": "https://office.com",
                    "iconName": "OfficeLogo",
                    "tableData": {
                        "id": 6
                    }
                },
                {
                    "name": "TN3270",
                    "description": "Mainframe Access",
                    "Url": "https://tn3270web/",
                    "iconName": "Database",
                    "tableData": {
                        "id": 7
                    }
                },
                {
                    "name": "My App",
                    "description": "Access to My App",
                    "Url": "https://www.google.pt",
                    "iconName": "PowerApps2Logo",
                    "tableData": {
                        "id": 8
                    }
                }
            ]
}

Update an Extension

To update an extension, we need to PATCH the extension created on the specified instance of a resource and on the property we want to update.

Sample of update a list of Applications of User.

PATCH https://graph.microsoft.com/v1.0/me/extensions/myapps
{
    "Apps": [
                {
                    "name": "My SAP",
                    "description": "SAP Access",
                    "Url": "https://www.sap.pt",
                    "iconName": "AppIconDefault",
                    "tableData": {
                        "id": 0
                    }
                },
                {
                    "name": "Q&A",
                    "description": "Quick Access",
                    "Url": "https://www.qa.pt",
                    "iconName": "SurveyQuestions",
                    "tableData": {
                        "id": 1
                    }
                },
                {
                    "name": "My Reports",
                    "description": "FI Reports 2",
                    "Url": "https://www.sap.pt",
                    "iconName": "CRMReport",
                    "tableData": {
                        "id": 2
                    }
                },
                {
                    "name": "My CRM",
                    "description": "CRM - Support",
                    "Url": "https://www.crm.pt",
                    "iconName": "AnalyticsView",
                    "tableData": {
                        "id": 3
                    }
                },
                {
                    "name": "Travels",
                    "description": "Travel Agencies",
                    "Url": "https://www.tap.pt",
                    "iconName": "AirplaneSolid",
                    "tableData": {
                        "id": 4
                    }
                },
                {
                    "name": "My Redmind",
                    "description": "Redmind",
                    "Url": "https://www.red.pt",
                    "iconName": "Help",
                    "tableData": {
                        "id": 5
                    }
                },
                {
                    "name": "Office 365",
                    "description": "My Office 365",
                    "Url": "https://office.com",
                    "iconName": "OfficeLogo",
                    "tableData": {
                        "id": 6
                    }
                },
                {
                    "name": "TN3270",
                    "description": "Mainframe Access",
                    "Url": "https://tn3270web/",
                    "iconName": "Database",
                    "tableData": {
                        "id": 7
                    }
                },
                {
                    "name": "My App 2",
                    "description": "Access to My App",
                    "Url": "https://www.google.pt",
                    "iconName": "PowerApps2Logo",
                    "tableData": {
                        "id": 8
                    }
                }
            ]
} 

Delete an Extension

To delete an extension, we need to do an DELETE on the extension created on the specified instance of a resource. This will delete the extension and its properties..

Sample:

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

Open extension limits

The following limits apply to directory resources (such as usergroupdevice):

  • Each open extension can have up to 2 KB of data (including the extension definition itself).
  • An application can add up to two open extensions per resource instance.

The following limits apply to Outlook resources (such as messageevent, and contact):

References:

Add custom data to resources using extensions

SPFx – My Personal Apps – Web Part

Thank you for reading!

%d bloggers gostam disto: