如果页面当前处于编辑模式,SharedPoint REST API validateupdatelistitem 会失败并返回 423 锁定错误。
几天前它就可以工作了,但似乎是在 SharePoint 新功能“页面共同创作”推出后。运行此 REST API 来更新字段“TaxKeyword”始终会返回 423 锁定错误。 错误:“文件“contoso.sharepoint.com/sites/abc/SitePages/Testing-keywords.aspx”已被锁定以供 [电子邮件受保护] 共享使用。”
我做了什么? 针对 SharePoint 运行以下发布请求。
我期望什么? 获取页面的 TaxKeyword 字段并使用关键字“Cairo”进行更新
注意事项: 该请求正在编辑 SharePoint 页面期间运行。
帖子:
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 }
当向 ValidateUpdateListItem 主体发出请求时,我在 SPFx Web 部件中遇到了同样的问题。我还在某些 SharePoint 字段的 OOTB 页面详细信息面板中看到过它。 我不完全确定您的情况,但也许下面的内容无论如何都会有帮助。
在启用共同创作的页面/环境中,ValidateUpdateListItem 请求正文必须具有
sharedLockId
属性,否则请求将失败并出现 423 Locked 错误。
编辑页面时,DOM 中有一个
spClientSidePageContext
JSON 对象。该对象包含另一个名为 CoAuthState
的对象,该对象又包含 sharedLockId
属性。
在 SPFX Web 部件中,我想您可以从 DOM 检索该值,但您也可以通过站点页面模块/组件检索它。
const sitePagesComponent = await SPComponentLoader.loadComponentById<any>("b6917cb1-93a0-4b97-a84d-7cf49975d4ec"); // This is the GUID for the Site Pages feature
if (sitePagesComponent?.PageStore?.fields) {
const sharedLockId = sitePagesComponent.PageStore.fields.SharedLockId;
}
我认为这应该被认为是不受支持的,如果进行内部更改,它可能会崩溃。但我找不到太多(任何)有关它的文档。
在正文中提供sharedLockId值,请求应该可以工作。此外,如果您的案例是 SPFx Web 部件,并且您使用 PnPJs 进行 ValidateUpdateListItem 请求,则您必须以其他方式发出请求,因为 PnPJs 实现目前不支持共享LockId 参数。
// example endpointUrl: https://contoso.sharepoint.com/sites/abc/_api/web/lists/getByTitle('Site Pages')/items(1)/ValidateUpdateListItem
export async function validateUpdateListItem(endpointUrl: string, context: WebPartContext, sharedLockId: string | null): Promise<string> {
try {
const body = {
bNewDocumentUpdate: true,
checkInComment: null,
sharedLockId: sharedLockId,
formValues: [ { "FieldName": "TaxKeyword", "FieldValue": "Cairo|12345678-3333-4444-b0c8-123456789012;" } ]
}
const optionsWithData: ISPHttpClientOptions = {
headers: {
'Accept': 'application/json;odata=verbose',
'Content-Type': 'application/json;odata=verbose',
'OData-Version': '',
},
body: JSON.stringify(body)
}
const client = context.spHttpClient;
const response: SPHttpClientResponse = await client.post(endpointUrl,
SPHttpClient.configurations.v1, optionsWithData);
const responseJson = await response.json();
const json = responseJson?.d ?? responseJson;
const result = json?.ValidateUpdateListItem?.results[0] ?? json.error;
return JSON.stringify(result);
} catch (error) {
return JSON.stringify(error);
}
}
我还创建了一个 Web 部件来探索/展示问题和解决方法: GitHub:spfx-共同创作-验证-更新-列表-项目