0

我在使用 _api/$batch 请求隔离批处理请求时遇到了一些麻烦。我确定只是发生了一些简单的错误/问题,但我不能只指出这一点。有任何想法吗?

以下是请求的原始邮递员控制台日志的一些片段:

POST /_api/$batch HTTP/1.1
Accept: application/json; odata=nometadata
Content-Type: multipart/mixed; boundary="batch_8215457c-c4fb-432a-abf6-7b1f86168c65"
Authorization: Bearer <token deleted>

--batch_8215457c-c4fb-432a-abf6-7b1f86168c65
Content-Type: multipart/mixed; boundary="changeset_d9097ba9-2d69-40ca-a301-90cf97aafb17"
Content-Transfer-Encoding: binary

--changeset_d9097ba9-2d69-40ca-a301-90cf97aafb17
Content-Type: application/http
Content-Transfer-Encoding: binary

DELETE https://myOrg.sharepoint.com/sites/mySite/_api/web/lists/getByTitle(myList)/items(27) HTTP/1.1
If-Match: *
Accept: application/json; odata=nometadata

--changeset_d9097ba9-2d69-40ca-a301-90cf97aafb17
Content-Type: application/http
Content-Transfer-Encoding: binary

DELETE https://myOrg.sharepoint.com/sites/mySite/_api/web/lists/getByTitle(myList)/items(30) HTTP/1.1
If-Match: *
Accept: application/json; odata=nometadata

--changeset_d9097ba9-2d69-40ca-a301-90cf97aafb17--

--batch_8215457c-c4fb-432a-abf6-7b1f86168c65--

我为每个要删除的项目返回的响应是 400 Bad Request,每个批处理响应还包含:{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message" :{"lang":"en-US","value":"无效请求。"}}}

--batchresponse_38add954-a201-4857-a6db-68067eb9bc0a
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 400 Bad Request
CONTENT-TYPE: application/json;odata=nometadata;streaming=true;charset=utf-8

{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Invalid request."}}}
--batchresponse_38add954-a201-4857-a6db-68067eb9bc0a
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 400 Bad Request
CONTENT-TYPE: application/json;odata=nometadata;streaming=true;charset=utf-8

{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Invalid request."}}}
--batchresponse_38add954-a201-4857-a6db-68067eb9bc0a--

我一直在挖掘并尝试了一些事情:

  • 尝试从每个变更集中删除“Accept: application/json; odata=nometadata”
  • 在请求内容类型/编码后尝试调整任何换行符
  • 我尝试将批处理中的一项作为单个删除请求执行(有效)
  • 比较了一些笔记/示例:(Andrew Connell 博客:https ://gist.github.com/andrewconnell/dcd89e694475b628d0c7 )

有帮助的眼睛能指出错误吗?

4

1 回答 1

1

这是我对文档的错误解释。

根据Microsoft 的文档,请求 URL 部分说明(强调我的):

请求 URL 由根服务 URL$batch选项组成;例如,https://fabrikam.sharepoint.com/_api/$batchhttps://fabrikam.office365.com/api/v1.0/me/$batch

但是,“根服务 URL”有点误导,因为它实际上应该是站点的URL。我会考虑根服务 URL:

https://myorg.sharepoint.com

所以,在我上面的例子中,它是:

POST <siteURL>/_api/$batch  

或者,更具体的示例:

POST https://yourorg.sharepoint.com/sites/mySite  HTTP/1.1

感谢所有对此提出想法的人。

于 2021-11-10T22:47:10.880 回答