I am trying to add and change extended properties of devices registered in AzureAD using C#. But I am getting the following error, I don't know why...
Below is the part about the Graph API call. I used the document provided by MS Docs as it is, and it works normally in Graph API Explorer.
[C# Code]
var device = await graphclient.Devices
.Request()
.Filter(ftr)
.Select("Id")
.GetAsync();
string objectId = device.CurrentPage.First().Id.ToString().Trim();
var extattr = new Device
{
AdditionalData = new Dictionary<string, object>(){
{"extensionAttributes", "{\"extensionAttribute1\":\"BYOD-Device2\"}"}
}
};
await graphclient.Devices[objectId]
.Request()
.UpdateAsync(extattr);
[ErrorCode]
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: Request_BadRequest
Message: A 'PrimitiveValue' node with non-null value was found when trying to read the value of the property 'extensionAttributes'; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected.
The current situation is that extensionAttribute1 has the value 'BYOD-Device'.
Is there anyone out there who can help me solve this error?
The value of the extensionAttribute1
property is not a JSON string, but a JSON object. Try
AdditionalData = new Dictionary<string, object>(){
{"extensionAttributes", new Dictionary<string, object>(){
{"extensionAttribute1", "BYOD-Device2"}
}}
}