SharePoint Online REST API $batch请求返回400 Invalid Request错误排查
核心错误点
1. 子请求使用了绝对URL
SharePoint Online /_api/$batch 接口要求所有批量内的子请求必须使用站点相对路径,不支持传入带域名的完整绝对URL。
你当前的错误写法:
DELETE https://myOrg.sharepoint.com/sites/mySite/_api/web/lists/getByTitle(myList)/items(27) HTTP/1.1
2. getByTitle参数缺少字符串标识
getByTitle 方法接收字符串类型的列表名,必须用单引号包裹参数值,未加引号的myList会被解析为未知变量,触发请求格式错误。
修正方案
将批量内的DELETE请求替换为相对路径、补充参数引号即可,可选补充Host头适配严格校验场景:
DELETE /sites/mySite/_api/web/lists/getByTitle('myList')/items(27) HTTP/1.1 Host: myOrg.sharepoint.com If-Match: *
完整修正后的请求示例
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 /sites/mySite/_api/web/lists/getByTitle('myList')/items(27) HTTP/1.1 Host: myOrg.sharepoint.com If-Match: * --changeset_d9097ba9-2d69-40ca-a301-90cf97aafb17 Content-Type: application/http Content-Transfer-Encoding: binary DELETE /sites/mySite/_api/web/lists/getByTitle('myList')/items(30) HTTP/1.1 Host: myOrg.sharepoint.com If-Match: * --changeset_d9097ba9-2d69-40ca-a301-90cf97aafb17-- --batch_8215457c-c4fb-432a-abf6-7b1f86168c65--
内容的提问来源于stack exchange,提问作者RobK
相关产品推荐
相关产品推荐

