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?
2
Answers
I tried to reproduce the same in my environment
When using spectfic
$filter
and$search
query parameters ,make sure to use the ConsistencyLevel header set to eventual and $count to trueHeaders:
C# code:
In azure ad extensionAttributes can be set while creation or updating device object.
And Supports
filter
when value is null
Get the device details:
I checked in one of my subscriptions with deviceId,
could get its details.
Normally new extension attribute can be created for which doesn’t have any previous value or value is null .
But here
extensionattribute1
has already had a value in your case.But as it already has some value , to update it either new extension with another number has to be created or that attribute has to be explicitly made null and then updated.
Reference: https://learn.microsoft.com/en-us/graph/api/resources/device?view=graph-rest-1.0
The value of the
extensionAttribute1
property is not a JSON string, but a JSON object. Try