首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不知道是什么导致了图形API调用的错误。

我不知道是什么导致了图形API调用的错误。
EN

Stack Overflow用户
提问于 2022-11-16 00:30:17
回答 2查看 78关注 0票数 0

我正在尝试使用AzureAD添加和更改在C#中注册的设备的扩展属性。但我得到了以下错误,我不知道为什么.

下面是有关Graph调用的部分。我使用了MS提供的文档,它在中正常工作。

C#码

代码语言:javascript
复制
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

代码语言:javascript
复制
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.

目前的情况是,extensionAttribute1的价值‘比亚迪-设备’。

有谁能帮我解决这个错误吗?

EN

回答 2

Stack Overflow用户

发布于 2022-11-21 13:02:22

我尝试在我的环境中复制相同的

当使用$filter$search查询参数时,请确保将ConsistencyLevel头设置为最终值,将$count设置为true

标题:

代码语言:javascript
复制
ConsistencyLevel=eventual 
$count=true

C#代码:

代码语言:javascript
复制
var queryOptions = new List<QueryOption>()
{
    new QueryOption("$count", "true"),
    new QueryOption("$search", "\"displayName:Android\"")
};
var device = await graphclient.Devices
    .Request()
    .Filter(ftr)
   .Header("ConsistencyLevel","eventual")
    .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);

在蓝色广告中,可以在创建或更新设备对象时设置extensionAttributes。

并支持filter when value is null

$filter ( eq,not,startsWith和eq对空值)。

获取设备详细信息:

我在deviceId上注册了一次订阅,可以得到它的详细信息。

通常,可以创建新的扩展属性,它没有任何以前的值,或者值是

但是在这里,extensionattribute1在您的例子中已经有了一个值。

代码语言:javascript
复制
"extensionAttributes": {
        "extensionAttribute1": "BYOD-Device",
        "extensionAttribute2": null,
        "extensionAttribute3": null,
        "extensionAttribute4": null,
        "extensionAttribute5": null,
        "extensionAttribute6": null,
        "extensionAttribute7": null,
       ...
}

但是,由于它已经有了一些价值,所以要更新它,必须创建带有另一个数字的新扩展,或者必须显式地使该属性为null,然后更新该属性。

代码语言:javascript
复制
 var queryOptions = new List<QueryOption>()
    {
        new QueryOption("$count", "true"),
        new QueryOption("$search", "\"displayName:Android\"")
    };
    var device = await graphclient.Devices
        .Request()
        .Filter(ftr)
       .Header("ConsistencyLevel","eventual")
        .Select("Id")
        .GetAsync();
    
    ......
DeviceId = "xxxxxxx",
     ....
    AdditionalData = new Dictionary<string, object>()
    {
        {"extensionAttributes", "{\"extensionAttribute1\":\"BYOD-Device\"}"}
    }
};

await graphClient.Devices
    .Request()
    .AddAsync(device)

还注意到,某些扩展属性在使用Linux操作系统时无法更新。

参考https://learn.microsoft.com/en-us/graph/api/resources/device?view=graph-rest-1.0

票数 0
EN

Stack Overflow用户

发布于 2022-11-21 13:08:10

extensionAttribute1属性的值不是JSON字符串,而是JSON对象。试一试

代码语言:javascript
复制
AdditionalData = new Dictionary<string, object>(){
    {"extensionAttributes", new Dictionary<string, object>(){
        {"extensionAttribute1", "BYOD-Device2"}
    }}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74453774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档