0
votes

What is the correct way to clear the content of a "simple" string property such as the description of a group using the Microsoft Graph .NET Client Library?

Setting a value that is not empty works fine with the following code

var patch = new Group();
patch.Description = "your description here";
var req = new GroupRequest(graphClient.Groups["<group id>"].Request().RequestUrl, graphClient, new List<Option>());
req.UpdateAsync(patch).Wait();

However, if I set patch.Description to "" i get an Exception

Code: Request_BadRequest Message: Invalid value specified for property 'description' of resource 'Group'.

If i set the value of patch.Description to null (which it already is for a new instance of Group()) nothing happens at all (I can also see in Fiddler, that no description is not contained in the body of the patch request).

So my question is, what is the correct way to clear a value?

2

2 Answers

6
votes

The correct way to clear a string attribute is to assign it null value. Your PATCH request didn't work as expected due to an issue with the service that was recently fixed. The client library doesn't send null values by default though. You can force it to send it by using the AdditionalData property bag:

var groupToUpdate = new Group();
//groupToUpdate.Description = "New description";
var prop = new Dictionary<string, object>();
prop.Add("description", null);
groupToUpdate.AdditionalData = prop; 
await graphClient.Groups[groupId].Request().UpdateAsync(groupToUpdate);
1
votes

At present, it is not support to update the Description property to null or empty. As a workaround, we can set it as a blank space. Here is an sample for your reference:

patch.Description = " ";

And if you want the Microsoft Graph to support to remove the Description, you can submit the feedback from here.