在网站的网站页面列表中创建页面

命名空间:microsoft.graph

网站中的网站页面列表中创建新的 sitePage

此 API 可用于以下国家级云部署

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考

权限类型 最低特权权限 更高特权权限
委派(工作或学校帐户) Sites.ReadWrite.All 不可用。
委派(个人 Microsoft 帐户) 不支持。 不支持。
应用程序 Sites.ReadWrite.All 不可用。

HTTP 请求

POST /sites/{site-id}/pages

请求标头

名称 说明
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权
Content-Type application/json. 必需。

请求正文

在请求正文中,提供要创建的 sitePage 资源的 JSON 表示形式。

备注:

  1. 若要确保成功分析请求正文, @odata.type=#microsoft.graph.sitePage 必须在请求正文中包含 。
  2. 如果使用 Get sitepage 操作的响应来创建 sitePage,建议添加 HTTP 标头 Accept: application/json;odata.metadata=none。 这将从响应中删除所有 OData 元数据。 还可以手动删除所有 OData 元数据。
  3. 使用 Microsoft 图形 API创建 sitePage 时,仅支持“支持的 Web 部件”部分中列出的 Web 部件。 尝试添加不受支持的 Web 部件将导致失败或异常。

支持的 Web 部件

有两种类型的 Web 部件可以添加到 sitePagestandardWebPartstextWebPart。 下表列出了标准 Web 部件支持的 Web 部件。

# Web 部件 类型
1 必应地图 e377ea37-9047-43b9-8cdb-a761be2f8e09
2 按钮 0f087d7f-520e-42b7-89c0-496aaf979d58
3 行动号召 df8e44e7-edd5-46d5-90da-aca1539313b8
4 2161a1c6-db61-4731-b97c-3cdb303f7cbb
5 文档嵌入 b7dd04e1-19ce-4b24-9132-b60a1c2b910d
6 图像 d1d91016-032f-456d-98a4-721247c305e8
7 映像库 af8be689-990e-492a-81f7-ba3e4cd3ed9c
8 链接预览 6410b3b6-d440-4663-8744-378976dc041e
9 组织结构图 e84a8ca2-f63c-4fb9-bc0b-d8eef5ccb22b
10 人员 7f718435-ee4d-431c-bdbf-9c4ff326f46e
11 快速链接 c70391ea-0b10-4ee9-b2b4-006d3fcad0cd
12 间隔 8654b779-4886-46d4-8ffb-b5ed960ee986
13 Youtube Embed 544dd15b-cf3c-441b-96da-004d5a8cea1d

响应

如果成功,此方法将 201 返回 和创建的 sitePage 对象。

示例

以下示例演示如何创建新页面。

请求

POST /sites/{site-id}/pages
Content-Type: application/json

{
  "@odata.type": "#microsoft.graph.sitePage",
  "name": "test.aspx",
  "title": "test",
  "pageLayout": "article",
  "showComments": true,
  "showRecommendedPages": false,
  "titleArea": {
    "enableGradientEffect": true,
    "imageWebUrl": "https://cdn.hubblecontent.osi.office.net/m365content/publish/005292d6-9dcc-4fc5-b50b-b2d0383a411b/image.jpg",
    "layout": "colorBlock",
    "showAuthor": true,
    "showPublishedDate": false,
    "showTextBlockAboveTitle": false,
    "textAboveTitle": "TEXT ABOVE TITLE",
    "textAlignment": "left",
    "imageSourceType": 2,
    "title": "sample1"
  },
  "canvasLayout": {
    "horizontalSections": [
      {
        "layout": "oneThirdRightColumn",
        "id": "1",
        "emphasis": "none",
        "columns": [
          {
            "id": "1",
            "width": 8,
            "webparts": [
              {
                "id": "6f9230af-2a98-4952-b205-9ede4f9ef548",
                "innerHtml": "<p><b>Hello!</b></p>"
              }
            ]
          },
          {
            "id": "2",
            "width": 4,
            "webparts": [
              {
                "id": "73d07dde-3474-4545-badb-f28ba239e0e1",
                "webPartType": "d1d91016-032f-456d-98a4-721247c305e8",
                "data": {
                  "dataVersion": "1.9",
                  "description": "Show an image on your page",
                  "title": "Image",
                  "properties": {
                    "imageSourceType": 2,
                    "altText": "",
                    "overlayText": "",
                    "siteid": "0264cabe-6b92-450a-b162-b0c3d54fe5e8",
                    "webid": "f3989670-cd37-4514-8ccb-0f7c2cbe5314",
                    "listid": "bdb41041-eb06-474e-ac29-87093386bb14",
                    "uniqueid": "d9f94b40-78ba-48d0-a39f-3cb23c2fe7eb",
                    "imgWidth": 4288,
                    "imgHeight": 2848,
                    "fixAspectRatio": false,
                    "captionText": "",
                    "alignment": "Center"
                  },
                  "serverProcessedContent": {
                    "imageSources": [
                      {
                        "key": "imageSource",
                        "value": "/_LAYOUTS/IMAGES/VISUALTEMPLATEIMAGE1.JPG"
                      }
                    ],
                    "customMetadata": [
                      {
                        "key": "imageSource",
                        "value": {
                          "siteid": "0264cabe-6b92-450a-b162-b0c3d54fe5e8",
                          "webid": "f3989670-cd37-4514-8ccb-0f7c2cbe5314",
                          "listid": "bdb41041-eb06-474e-ac29-87093386bb14",
                          "uniqueid": "d9f94b40-78ba-48d0-a39f-3cb23c2fe7eb",
                          "width": "4288",
                          "height": "2848"
                        }
                      }
                    ]
                  }
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

响应

如果成功,此方法在所创建页面的响应正文中返回 sitePage

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.type": "microsoft.graph.sitePage",
    "id": "0dd6ddd6-45bd-4acd-b683-de0e6e7231b7",
    "name": "test.aspx",
    "webUrl": "https://contoso.sharepoint.com/SitePages/test.aspx",
    "title": "test",
    "pageLayout": "article",
    "showComments": true,
    "showRecommendedPages": false,
    "createdBy": {
      "user": {
          "displayName": "Rahul Mittal",
          "email": "rahmit@contoso.com"
      }
    },
    "lastModifiedBy": {
      "user": {
          "displayName": "Rahul Mittal",
          "email": "rahmit@contoso.com"
      }
    },
    "publishingState": {
      "level": "checkout",
      "versionId": "0.1",
      "checkedOutBy": {
        "user": {
          "displayName": "Rahul Mittal",
          "email": "rahmit@contoso.com"
        }
      }
    },
    "titleArea": {
        "enableGradientEffect": true,
        "imageWebUrl": "https://cdn.hubblecontent.osi.office.net/m365content/publish/005292d6-9dcc-4fc5-b50b-b2d0383a411b/image.jpg",
        "layout": "colorBlock",
        "showAuthor": true,
        "showPublishedDate": false,
        "showTextBlockAboveTitle": false,
        "textAboveTitle": "TEXT ABOVE TITLE",
        "textAlignment": "left",
        "title": "sample4",
        "imageSourceType": 2
    }
}

注意:为清楚起见,将截断 Response 对象。 实际调用会返回默认属性。