使用 GraphClient 在 365 组上设置自定义属性
Setting custom properties on an 365 group with GraphClient
我想在 265 组上设置 CustomProperty5。我有以下代码:
var extensions = await graphClient.Groups["xxx"].Extensions.Request().GetAsync();
var dictionary = new Dictionary<string, object>();
dictionary.Add("CustomAttribute5", "Works!");
await graphClient
.Groups["xxx"]
.Request()
.UpdateAsync(new Microsoft.Graph.Group()
{
AdditionalData = dictionary
});
但是我收到以下错误:
Microsoft.Graph.ServiceException: 'Code: Request_BadRequest Message:
One or more property values specified are invalid.
任何关于如何在 365 群组上设置自定义属性的指示?
对于现有组 open extension could be updated 这样通过 msgraph-sdk-dotnet
:
//retrieve an existing group custom property
var ext = await graphClient.Groups[groupId].Extensions[extName].Request().GetAsync();
//update
ext.AdditionalData = new Dictionary<string, object>()
{
{
"status", "Closed"
}
};
await graphClient.Groups[groupId].Extensions[extName]
.Request()
.UpdateAsync(ext);
当涉及到complex type extension时,可以通过组更新端点进行更新。假设注册了以下类型扩展:
{
"id":"contoso_grpstatus",
"description": "",
"targetTypes": [
"Group"
],
"properties": [
{
"name": "Status",
"type": "String"
}
]
}
然后可以像这样更新定义了 contoso_grpstatus
复杂类型扩展的现有组实例:
var group = new Group
{
AdditionalData = new Dictionary<string, object>()
{
{
"contoso_grpstatus", new Dictionary<string, object>()
{
{"Status", "Closed"}
}
}
}
};
await graphClient.Groups[groupId]
.Request()
.UpdateAsync(group);
我想在 265 组上设置 CustomProperty5。我有以下代码:
var extensions = await graphClient.Groups["xxx"].Extensions.Request().GetAsync();
var dictionary = new Dictionary<string, object>();
dictionary.Add("CustomAttribute5", "Works!");
await graphClient
.Groups["xxx"]
.Request()
.UpdateAsync(new Microsoft.Graph.Group()
{
AdditionalData = dictionary
});
但是我收到以下错误:
Microsoft.Graph.ServiceException: 'Code: Request_BadRequest Message: One or more property values specified are invalid.
任何关于如何在 365 群组上设置自定义属性的指示?
对于现有组 open extension could be updated 这样通过 msgraph-sdk-dotnet
:
//retrieve an existing group custom property
var ext = await graphClient.Groups[groupId].Extensions[extName].Request().GetAsync();
//update
ext.AdditionalData = new Dictionary<string, object>()
{
{
"status", "Closed"
}
};
await graphClient.Groups[groupId].Extensions[extName]
.Request()
.UpdateAsync(ext);
当涉及到complex type extension时,可以通过组更新端点进行更新。假设注册了以下类型扩展:
{
"id":"contoso_grpstatus",
"description": "",
"targetTypes": [
"Group"
],
"properties": [
{
"name": "Status",
"type": "String"
}
]
}
然后可以像这样更新定义了 contoso_grpstatus
复杂类型扩展的现有组实例:
var group = new Group
{
AdditionalData = new Dictionary<string, object>()
{
{
"contoso_grpstatus", new Dictionary<string, object>()
{
{"Status", "Closed"}
}
}
}
};
await graphClient.Groups[groupId]
.Request()
.UpdateAsync(group);