You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Graph API获取SharePoint页面布局?请求报错求助

问题:Graph API调用获取SharePoint页面布局返回itemNotFound错误

我尝试通过Graph API获取SharePoint子站点的页面布局时收到itemNotFound错误,但通过网页可以正常访问母版页库。

请求的API地址:

https://graph.microsoft.com/v1.0/sites/{site-id}/sites/{sub-site-id}/drive/root:/_catalogs/masterpage/PageLayouts:/children

返回错误信息:

{
    "error": {
        "code": "itemNotFound",
        "message": "The resource could not be found.",
        "innerError": {
            "date": "2023-03-14T18:01:31",
            "request-id": "a05bc326-02e9-4fad-ad92-cfb62144161d",
            "client-request-id": "4958fc74-4d2e-7bc0-6fbc-a7f1a0cccad3"
        }
    }
}

排查与解决方法

  • 验证站点ID准确性
    确认{site-id}和{sub-site-id}的格式与取值正确。子站点ID可通过调用GET https://graph.microsoft.com/v1.0/sites/{site-id}/sites获取,必须使用返回结果中id字段的完整值,而非站点自定义名称。

  • 调整API路径结构
    原请求通过嵌套/sites/{sub-site-id}定位子站点,可改为直接通过子站点ID获取其Drive:

    https://graph.microsoft.com/v1.0/sites/{sub-site-id}/drive/root:/_catalogs/masterpage/PageLayouts:/children
    

    每个子站点拥有独立Drive,嵌套路径可能导致资源定位偏差。

  • 检查API权限配置
    确保应用已分配Sites.Read.All或Sites.ReadWrite.All权限(委托/应用权限二选一,根据认证方式决定),且应用权限已完成管理员同意。可通过Graph Explorer测试相同请求,快速排除权限问题。

  • 确认文件夹路径正确性
    部分SharePoint环境中,页面布局文件夹可能位于/_catalogs/masterpage/下的语言区域子文件夹,或母版页库结构被自定义修改。先调用以下接口查看母版页库根目录内容:

    https://graph.microsoft.com/v1.0/sites/{sub-site-id}/drive/root:/_catalogs/masterpage:/children
    

    确认PageLayouts文件夹的实际名称与路径。

  • 改用站点列表端点获取
    母版页库本质是SharePoint列表,可通过列表接口直接获取页面布局:

    https://graph.microsoft.com/v1.0/sites/{sub-site-id}/lists/masterpage/items?expand=fields
    

    该方式绕开Drive路径定位问题,直接针对母版页库资源。


内容的提问来源于stack exchange,提问作者Madhu Nali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 06:42:14