【问题标题】:Microsoft Graph SDK error while attempting to create a new SharePoint list item尝试创建新的 SharePoint 列表项时出现 Microsoft Graph SDK 错误
【发布时间】:2021-08-23 17:48:42
【问题描述】:

我一直在尝试通过 SDK 创建一个 SharePoint 列表项。 SDK 请求在功能上与C# documentation for this type of request. 相同

await client
.Sites[siteId]
.Lists[listId]
.Items
.Request()
.AddAsync(new ListItem
{
    Fields = new FieldValueSet
    {
        AdditionalData = new Dictionary<string, object>
        {
            { "Title", "Test" },
            { "Salary", true },
        }
    }
});

我不断收到以下 500 错误:

    "Error": {
            "code": "generalException",
            "message": "General exception while processing",
            "innererror": {
                "date": "2021-08-23T17:13:20",
                "request-id": "3602eb54-5bde-49ac-abde-16078102746b",
                "client-request-id": "3602eb54-5bde-49ac-abde-16078102746b"
            }
        }

但是,如果我通过 Postman 执行此请求,则请求会成功完成,并且我会看到创建的列表项。

POST https://graph.microsoft.com/v1.0/Sites/[siteid]/lists/[listid]/items
SdkVersion: postman-graph/v2.0
Authorization: Bearer [token]
Content-Type: application/json
User-Agent: PostmanRuntime/7.28.3
Cache-Control: no-cache
Host: graph.microsoft.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 32
Request Body
{ 
    "fields" : {
        "Title" : "Test",
        "Salary" : true
    }
}

是不是我做错了什么?

【问题讨论】:

  • 通过 Fiddler 捕获传出请求并比较两者。

标签: c# microsoft-graph-sdks


【解决方案1】:

我想通了。尽管字典AdditionalData 字段采用Dictionary&lt;string, object&gt;,但SDK 只能在值是字符串时处理它。

传递布尔值会导致错误。我只需要将 `.ToString()' 添加到我的所有值中,它现在就可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 2019-04-22
    • 2019-07-13
    • 2021-11-18
    • 2018-08-16
    相关资源
    最近更新 更多