SharePoint REST API 联机批处理请求问题:收到 400 错误请求,odata.error 无效请求
SharePoint REST API Online batch request issues : getting 400 Bad Request, odata.error Invalid request
我在使用 _api/$batch 请求隔离批处理请求时遇到了一些问题。我确定只有一些简单的 mistake/issue 正在发生,但我无法确定这一点。有什么想法吗?
以下是请求的原始邮递员控制台日志的一些片段:
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,每个 Batch 响应还包含:
{"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--
我一直在挖掘并尝试了一些东西:
- 尝试从每个变更集中删除“接受:application/json;odata=nometadata”
- 尝试在请求后调整任何换行符content-type/encoding
- 我尝试将批处理中的一个项目作为单个删除请求执行(有效)
- 比较了一些 notes/examples:(Andrew Connell 博客:https://gist.github.com/andrewconnell/dcd89e694475b628d0c7)
有大神能指出错误吗?
这是我对文档的错误解释。
根据 Microsoft's documentation,请求 URL 部分指出(强调我的):
The request URL consists of the root service URL and the $batch
option; for example, https://fabrikam.sharepoint.com/_api/$batch or https://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
感谢所有对此进行思考的人。
我在使用 _api/$batch 请求隔离批处理请求时遇到了一些问题。我确定只有一些简单的 mistake/issue 正在发生,但我无法确定这一点。有什么想法吗?
以下是请求的原始邮递员控制台日志的一些片段:
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,每个 Batch 响应还包含: {"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--
我一直在挖掘并尝试了一些东西:
- 尝试从每个变更集中删除“接受:application/json;odata=nometadata”
- 尝试在请求后调整任何换行符content-type/encoding
- 我尝试将批处理中的一个项目作为单个删除请求执行(有效)
- 比较了一些 notes/examples:(Andrew Connell 博客:https://gist.github.com/andrewconnell/dcd89e694475b628d0c7)
有大神能指出错误吗?
这是我对文档的错误解释。
根据 Microsoft's documentation,请求 URL 部分指出(强调我的):
The request URL consists of the root service URL and the
$batch
option; for example, https://fabrikam.sharepoint.com/_api/$batch or https://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
感谢所有对此进行思考的人。