使用 Microsoft Graph 获取用户的扩展属性属性、用户、Microsoft、Graph

2023-09-06 17:28:27 作者:你是我最致命的爱

我正在使用 Microsoft Graph 来管理 Azure AD 用户,但在访问用户对象上的扩展属性时遇到了一些问题.该属性是在使用 Azure AD Graph API 创建用户时添加的,如果您使用 Azure AD API 查询用户,则会自动返回扩展属性,名称为extension_{appId}_{propertyName}".我想使用 Microsoft Graph 访问此属性的值,但没有找到正确的调用方法.

I am working with Microsoft Graph to manage Azure AD users and am having some trouble accessing extension properties on a User object. The property was added when the user was created using Azure AD Graph API and if you query the user using Azure AD API the extension property is automatically returned with the name "extension_{appId}_{propertyName}". I would like to access the value of this property using Microsoft Graph but haven’t found the correct call to do so.

我尝试使用 $select 直接选择属性(按上面列出的全名)和较短的名称.https://graph.microsoft.com/beta/Users/{id}?$select=extension_{appId}_{propertyName}

I have tried using $select to select the property directly (by the full name listed above) and the shorter name. https://graph.microsoft.com/beta/Users/{id}?$select=extension_{appId}_{propertyName}

我也尝试使用 $expand 查询 singleValueExtendedProperty(和 multiValue),但被告知该属性在用户对象上不存在.https://graph.microsoft.com/beta/Users/{id}?$expand=singleValueExtendedProperty

I have also tried querying the singleValueExtendedProperty (and multiValue) with $expand but am told the property does not exist on a User object. https://graph.microsoft.com/beta/Users/{id}?$expand=singleValueExtendedProperty

我也玩过用户对象上的扩展"字段,但它总是为空.

I have also played around with the 'extensions' field on the User object but that is always just null.

只是好奇 Graph 是否支持此操作,如果支持,如何查询该字段.如果我可以在查询用户组时获得此扩展程序的值而无需运行单独的查询,那将是一个奖励.

Just curious if Graph supports this operation and if so, how to query that field. It would be a bonus if I could get the value of this extension when querying for groups of users without having to run a separate query.

推荐答案

扩展显示在 Microsoft Graph 中的 Extensions 集合中,而不是顶级属性:

Extensions show up in Microsoft Graph within the Extensions collection, not are top-level properties:

"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,mail,extensions)/$entity",
"id": "16f5a7b6-5a15-4568-aa5a-31bb117e9967",
"displayName": "Anne Weiler",
"mail": "annew@CIE493742.onmicrosoft.com",
"extensions@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('16f5a7b6-5a15-4568-aa5a-31bb117e9967')/extensions",
"extensions": [
    {
        "@odata.type": "#microsoft.graph.openTypeExtension",
        "theme": "dark",
        "color": "purple",
        "lang": "Japanese",
        "extensionName": "com.contoso.roamingSettings",
        "id": "com.contoso.roamingSettings"
    }
]

例如,您可以使用以下查询返回 users 集合(包括任何扩展名):v1.0/users?$select=id,displayName,mail&$expand=extensions(参见 Graph Explorer)

For example, you can use the following query to return a collection of users (including any extensions): v1.0/users?$select=id,displayName,mail&$expand=extensions (see in Graph Explorer)