msgraph-sdk-dotnet
msgraph-sdk-dotnet copied to clipboard
Can't delete single-value extended property for calendar
Describe the bug Can't delete single-value extended property for calendar.
To Reproduce I have created a single-value extended property for my default calendar.
Code to set value for calendar:
var userConfig = JsonConvert.SerializeObject(data);
var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";
var customProperty = new SingleValueLegacyExtendedProperty
{
Id = propertyId,
Value = userConfig
};
var calendar = await _graphClient.Users[data.User.UserId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();
var updateCalendar = new Calendar
{
Id = calendar.Id
};
var extendedValueCollection = new CalendarSingleValueExtendedPropertiesCollectionPage {customProperty};
updateCalendar.SingleValueExtendedProperties = extendedValueCollection;
await _graphClient.Users[data.User.UserId].Calendar.Request().UpdateAsync(updateCalendar);
Code to remove value:
var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";
var calendar = await _graphClient.Users[userId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();
var updateCalendar = new Calendar
{
Id = calendar.Id
};
updateCalendar.SingleValueExtendedProperties = null;
await _graphClient.Users[userId].Calendar.Request().UpdateAsync(updateCalendar);
Code to read value:
var value = string.Empty;
var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";
var calendar = await _graphClient.Users[userId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();
var properties = calendar.SingleValueExtendedProperties;
if (properties == null)
{
return value;
}
var customProperty = properties.CurrentPage.First();
value = customProperty.Value;
if (string.IsNullOrEmpty(value))
{
_log.LogInformation($"No config for user {userId} found");
}
_log.LogInformation($"Config for user {userId} found: {userId}");
return value;
Expected behavior
The value for the extended calendar property should be null. Instead I get the following JSON:
Desktop (please complete the following information):
- OS: Windows 10
- Postman AB#7245
When you call await _graphClient.Users[userId].Calendar.Request().UpdateAsync(updateCalendar);
, what are you seeing for the request and response? Are you able to make the update using Graph Explorer.
A quick look at the docs shows me little about this scenario.
https://docs.microsoft.com/en-us/graph/api/resources/singlevaluelegacyextendedproperty?view=graph-rest-beta
You may get better answer coverage on StackOverflow for this question. I suggest that you x-post and add a link here.
@MIchaelMainer thx for your quick response. In the meantime I found a solution to delete the single-value extended property for the calendar. Nevertheless I am convinced that this is a bug.
Code to delete property:
var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";
var customProperty = new SingleValueLegacyExtendedProperty
{
Id = propertyId,
Value = null // set null to delete single-value extended property
};
var calendar = await _graphClient.Users[userId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();
var updateCalendar = new Calendar
{
Id = calendar.Id
};
var extendedValueCollection = new CalendarSingleValueExtendedPropertiesCollectionPage {customProperty};
updateCalendar.SingleValueExtendedProperties = extendedValueCollection;
await _graphClient.Users[userId].Calendar.Request().UpdateAsync(updateCalendar);;
closing older issues. Please reopen if occurs on V5 or greater.