Thomas Segato
Thomas Segato

Reputation: 5213

Setting custom properties on an 365 group with GraphClient

I want to set CustomProperty5 on a 265 group. I have following code:

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

});

However I get following error:

Microsoft.Graph.ServiceException: 'Code: Request_BadRequest Message: One or more property values specified are invalid.

Any pointers how to set custom properties on a 365 group?

Upvotes: 1

Views: 428

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59318

For existing group open extension could be updated like this via 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);

When it comes to complex type extension, it could be updated via group update endpoint. Lets assume the following type extension is registered:

{
    "id":"contoso_grpstatus",
    "description": "",
    "targetTypes": [
        "Group"
    ],
    "properties": [
        {
            "name": "Status",
            "type": "String"
        }
    ]
}

Then an existing group instance with the contoso_grpstatus complex type extension defined could be updated like this:

var group = new Group
{
     AdditionalData = new Dictionary<string, object>()
     {
          {
                "contoso_grpstatus", new Dictionary<string, object>()
                {
                    {"Status", "Closed"}
                }
          }
     }
};
await graphClient.Groups[groupId]
         .Request()
         .UpdateAsync(group);

Upvotes: 1

Related Questions