Create a page in the site pages list of a site

Namespace: microsoft.graph

Create a new sitePage in the site pages list in a site.

This API is available in the following national cloud deployments.

Global service US Government L4 US Government L5 (DOD) China operated by 21Vianet

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

Permission type Least privileged permissions Higher privileged permissions
Delegated (work or school account) Sites.ReadWrite.All Not available.
Delegated (personal Microsoft account) Not supported. Not supported.
Application Sites.ReadWrite.All Not available.

HTTP request

POST /sites/{site-id}/pages

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.
Content-Type application/json. Required.

Request body

In the request body, supply a JSON representation of the sitePage resource to create.

Notes: :

  1. To ensure successful parsing of the request body, the @odata.type=#microsoft.graph.sitePage must be included in the request body.
  2. If you're using the response from the Get sitepage operation to create a sitePage, we recommend that you add the HTTP header Accept: application/json;odata.metadata=none. This will remove all OData metadata from the response. You can also manually remove all OData metadata.
  3. Only the web part listed in the Supported web parts section are supported when creating a sitePage using the Microsoft Graph API. Attempting to add unsupported web parts will result in a failure or exception.

Supported web parts

There are two kinds of web parts that can be added to a sitePage: standardWebParts and textWebPart. The following table lists the supported web parts for standard web parts.

# Web Part Type
1 Bing Maps e377ea37-9047-43b9-8cdb-a761be2f8e09
2 Button 0f087d7f-520e-42b7-89c0-496aaf979d58
3 Call To Action df8e44e7-edd5-46d5-90da-aca1539313b8
4 Divider 2161a1c6-db61-4731-b97c-3cdb303f7cbb
5 Document Embed b7dd04e1-19ce-4b24-9132-b60a1c2b910d
6 Image d1d91016-032f-456d-98a4-721247c305e8
7 Image Gallery af8be689-990e-492a-81f7-ba3e4cd3ed9c
8 Link Preview 6410b3b6-d440-4663-8744-378976dc041e
9 Org Chart e84a8ca2-f63c-4fb9-bc0b-d8eef5ccb22b
10 People 7f718435-ee4d-431c-bdbf-9c4ff326f46e
11 Quick Links c70391ea-0b10-4ee9-b2b4-006d3fcad0cd
12 Spacer 8654b779-4886-46d4-8ffb-b5ed960ee986
13 Youtube Embed 544dd15b-cf3c-441b-96da-004d5a8cea1d
14 Title Area cbe7b0a9-3504-44dd-a3a3-0e5cacd07788

Response

If successful, this method returns a 201 and the created sitePage object.

Example

The following example shows how to create a new page.

Request

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"
                        }
                      }
                    ]
                  }
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

Response

If successful, this method returns a sitePage in the response body for the created page.

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
    }
}

Note: The response object is truncated for clarity. Default properties will be returned from the actual call.