MS Graph 批处理创建列表项 (SPO) 无效的批处理有效负载格式 [英] MS Graph batching create list item (SPO) Invalid batch payload format

查看:63
本文介绍了MS Graph 批处理创建列表项 (SPO) 无效的批处理有效负载格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实看到了同样的错误,在 c# 中有一个未解决的问题,但我使用的是 PowerShell 并使用 POST 而不是 PATCH,所以我打开了一个单独的问题.

I did see this same error, in c# has an open question, but I'm using PowerShell and using POST rather than PATCH so I've opened a separate question.

我在使用 JSON 批处理时遇到问题,特别是当我包含 Content-Type 的标头时,我收到:

I'm having an issue when using JSON batching, particularly that when I include the header for Content-Type, I receive:

Invoke-RestMethod : {
  "error": {
    "code": "BadRequest",
    "message": "Invalid batch payload format.",
    "innerError": {
      "date": "2020-10-14T00:25:46",
      "request-id": "aa535dbb-efe8-450e-911d-143554ed9027",
      "client-request-id": "aa535dbb-efe8-450e-911d-143554ed9027"
    }
  }
}

我第一次完全没有包含标题,并且收到了错误:

I first had missed including the headers at all, and was receiving the error:

{
  "error": {
    "code": "BadRequest",
    "message": "Write request id : 2 does not contain Content-Type header or body.",
    "innerError": {
      "date": "2020-10-14T00:46:58",
      "request-id": "3601be6d-a861-4947-936b-451cd9de80c3",
      "client-request-id": "3601be6d-a861-4947-936b-451cd9de80c3"
    }
  }
}

我对 https://graph.microsoft.com/v1 的 HTTP 请求的正文.0/$batch 是一个 PSCustomObjects 数组,如下所示:

The body of my HTTP request to https://graph.microsoft.com/v1.0/$batch is an array of PSCustomObjects that look like this:

id     : 1
method : POST
url    : sites/8c3cb1ef-4116-b0e4-6d0b-25d0f333a4ed/lists/a2b2d34e-6d32-df22-d562-472d3d8385d2/items
body   : {
             "fields":  {
                            "DisplayName":  "user1@contoso.com",
                            "CreatedDateTime":  "2019-10-13",
                            "UserId":  "c963d785-59fc-4384-5e7d-d466=2118e3347",
                            "UserType":  "Guest",
                        }
         }
headers : {
              "Content-Type":  "application/json"
          }

我发现很奇怪,当我省略标头时,有效负载似乎没问题,但它看到尚未提供 Content-Type.一旦我添加它,然后突然有效载荷就不行了.

I found it odd that when I omit headers, the payload is seemingly OK, and it sees that Content-Type has not been supplied. Once I add it in, then suddenly payload is not OK.

如果我单独执行请求,所有相同的数据,也很好(在 SPO 列表中创建的项目没有问题).我觉得这个事实证实了问题不在于正文中的字段.

If I individually perform the requests, all the same data, it's also fine (items create in SPO list without issue). I feel like this fact confirms that the issue is not with the fields in the body.

我在批处理 GET 请求时没有问题(例如,批处理 100 个对 auditLogs/signIns 的请求).它们本质上是相同的有效负载,没有正文/标题,所以只有 id、url 和方法.

I have no issues when batching GET requests (e.g. batching 100's of requests for auditLogs/signIns). These are essentially the same payload, minus no body/headers, so just id, url, and method.

有没有人遇到过这种情况并找到了解决方案?

Has anyone had any experienced this and found a solution?

附注.Guid 都是假的.

PS. The Guid's are all fakes.

推荐答案

我的问题最终是我需要使用 ConvertTo-Json 的 -Depth 参数来成功捕获我身体的所有内容.它有 5 层深(请求:[每个请求:{正文:{字段:{字段名称/值}}}]).

My issue ended up being that I needed to use ConvertTo-Json's -Depth parameter to successfully capture all of my body's content. It was 5 levels deep (Requests: [ Each Request: { body: { fields: { field names/values } } } ]).

这只是 POST 方法请求的一个问题,因为那时需要一个主体,在这种情况下用于添加 SPO 列表项,这需要字段:带有子名称和列表列/单元格值的键.

This was only an issue with POST method requests, since a body is then needed, which in this case was for adding SPO list items, which requires the fields: key with children names and values for the list's columns / cells.

这篇关于MS Graph 批处理创建列表项 (SPO) 无效的批处理有效负载格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆