SharePoint REST API ValidateUpdateListItem报423锁定错误问题咨询
问题背景
当SharePoint页面处于编辑模式时,调用REST接口ValidateUpdateListItem更新TaxKeyword字段会返回423锁定错误,提示文件被特定用户锁定。该接口此前可正常工作,自SharePoint新增Page Co-Authoring(页面协同编辑)功能后出现此问题。
涉及请求信息:
- 请求地址:
https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1)/ValidateUpdateListItem - 请求体:
{ "formValues": [ { "FieldName": "TaxKeyword", "FieldValue": "Cairo|12345678-3333-4444-b0c8-123456789012;" } ], "bNewDocumentUpdate": true, "checkInComment": null }
问题原因
Page Co-Authoring功能启用后,页面进入编辑模式时会自动添加协同编辑锁定(LockType=2),而ValidateUpdateListItem接口默认不会处理这种锁定状态,因此触发423错误。
解决方案
方案1:先解锁页面再执行更新
获取页面锁定状态
发送GET请求检查页面是否处于协同锁定:GET https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1)/File/LockInfo若返回的
LockType值为2,说明是协同编辑锁定。解锁页面
发送POST请求解除锁定:POST https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1)/File/Unlock执行原更新请求
解锁完成后,重新调用原来的ValidateUpdateListItem请求即可。
方案2:通过签出-更新-签入流程处理
签出页面
POST https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1)/File/CheckOut执行更新请求
调整请求体的bNewDocumentUpdate为false,添加签入注释:POST https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1)/ValidateUpdateListItem Content-Type: application/json { "formValues": [ { "FieldName": "TaxKeyword", "FieldValue": "Cairo|12345678-3333-4444-b0c8-123456789012;" } ], "bNewDocumentUpdate": false, "checkInComment": "更新TaxKeyword字段" }签入页面
POST https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1)/File/CheckIn(comment='更新TaxKeyword字段', checkinType=0)(
checkinType=0为普通签入,1为覆盖签入,2为弃签)
方案3:使用列表项Update接口替代
直接调用列表项的MERGE接口更新字段,该接口可自动处理协同锁定冲突:
POST https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1) Content-Type: application/json IF-MATCH: * X-HTTP-Method: MERGE { "TaxKeyword": { "__metadata": { "type": "SP.Taxonomy.TaxonomyFieldValue" }, "Label": "Cairo", "TermGuid": "12345678-3333-4444-b0c8-123456789012", "WssId": -1 } }
注意请求头需包含IF-MATCH: *以覆盖锁定状态。
内容的提问来源于stack exchange,提问作者Mohammad Amer
相关产品推荐
相关产品推荐

