One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
The following example shows how to create a new page.
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": "/_LAYOUTS/IMAGES/VISUALTEMPLATETITLEIMAGE.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"
}
}
]
}
}
}
]
}
]
}
]
}
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new SitePage
{
OdataType = "#microsoft.graph.sitePage",
Name = "test.aspx",
Title = "test",
PageLayout = PageLayoutType.Article,
ShowComments = true,
ShowRecommendedPages = false,
TitleArea = new TitleArea
{
EnableGradientEffect = true,
ImageWebUrl = "/_LAYOUTS/IMAGES/VISUALTEMPLATETITLEIMAGE.JPG",
Layout = TitleAreaLayoutType.ColorBlock,
ShowAuthor = true,
ShowPublishedDate = false,
ShowTextBlockAboveTitle = false,
TextAboveTitle = "TEXT ABOVE TITLE",
TextAlignment = TitleAreaTextAlignmentType.Left,
AdditionalData = new Dictionary<string, object>
{
{
"imageSourceType" , 2
},
{
"title" , "sample1"
},
},
},
CanvasLayout = new CanvasLayout
{
HorizontalSections = new List<HorizontalSection>
{
new HorizontalSection
{
Layout = HorizontalSectionLayoutType.OneThirdRightColumn,
Id = "1",
Emphasis = SectionEmphasisType.None,
Columns = new List<HorizontalSectionColumn>
{
new HorizontalSectionColumn
{
Id = "1",
Width = 8,
Webparts = new List<WebPart>
{
new WebPart
{
Id = "6f9230af-2a98-4952-b205-9ede4f9ef548",
AdditionalData = new Dictionary<string, object>
{
{
"innerHtml" , "<p><b>Hello!</b></p>"
},
},
},
},
},
new HorizontalSectionColumn
{
Id = "2",
Width = 4,
Webparts = new List<WebPart>
{
new WebPart
{
Id = "73d07dde-3474-4545-badb-f28ba239e0e1",
AdditionalData = new Dictionary<string, object>
{
{
"webPartType" , "d1d91016-032f-456d-98a4-721247c305e8"
},
{
"data" , new
{
DataVersion = "1.9",
Description = "Show an image on your page",
Title = "Image",
Properties = new
{
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 = new
{
ImageSources = new List<object>
{
new
{
Key = "imageSource",
Value = "/_LAYOUTS/IMAGES/VISUALTEMPLATEIMAGE1.JPG",
},
},
CustomMetadata = new List<object>
{
new
{
Key = "imageSource",
Value = new
{
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",
},
},
},
},
}
},
},
},
},
},
},
},
},
},
};
var result = await graphClient.Sites["{site-id}"].Pages.PostAsync(requestBody);
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc-beta sites pages create --site-id {site-id} --body '{\
"@odata.type": "#microsoft.graph.sitePage",\
"name": "test.aspx",\
"title": "test",\
"pageLayout": "article",\
"showComments": true,\
"showRecommendedPages": false,\
"titleArea": {\
"enableGradientEffect": true,\
"imageWebUrl": "/_LAYOUTS/IMAGES/VISUALTEMPLATETITLEIMAGE.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"\
}\
}\
]\
}\
}\
}\
]\
}\
]\
}\
]\
}\
}\
'
const options = {
authProvider,
};
const client = Client.init(options);
const baseSitePage = {
'@odata.type': '#microsoft.graph.sitePage',
name: 'test.aspx',
title: 'test',
pageLayout: 'article',
showComments: true,
showRecommendedPages: false,
titleArea: {
enableGradientEffect: true,
imageWebUrl: '/_LAYOUTS/IMAGES/VISUALTEMPLATETITLEIMAGE.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'
}
}
]
}
}
}
]
}
]
}
]
}
};
await client.api('/sites/{site-id}/pages')
.version('beta')
.post(baseSitePage);
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SitePage();
$requestBody->setOdataType('#microsoft.graph.sitePage');
$requestBody->setName('test.aspx');
$requestBody->setTitle('test');
$requestBody->setPageLayout(new PageLayoutType('article'));
$requestBody->setShowComments(true);
$requestBody->setShowRecommendedPages(false);
$titleArea = new TitleArea();
$titleArea->setEnableGradientEffect(true);
$titleArea->setImageWebUrl('/_LAYOUTS/IMAGES/VISUALTEMPLATETITLEIMAGE.JPG');
$titleArea->setLayout(new TitleAreaLayoutType('colorBlock'));
$titleArea->setShowAuthor(true);
$titleArea->setShowPublishedDate(false);
$titleArea->setShowTextBlockAboveTitle(false);
$titleArea->setTextAboveTitle('TEXT ABOVE TITLE');
$titleArea->setTextAlignment(new TitleAreaTextAlignmentType('left'));
$additionalData = [
'imageSourceType' => 2,
'title' => 'sample1',
];
$titleArea->setAdditionalData($additionalData);
$requestBody->setTitleArea($titleArea);
$canvasLayout = new CanvasLayout();
$horizontalSectionsHorizontalSection1 = new HorizontalSection();
$horizontalSectionsHorizontalSection1->setLayout(new HorizontalSectionLayoutType('oneThirdRightColumn'));
$horizontalSectionsHorizontalSection1->setId('1');
$horizontalSectionsHorizontalSection1->setEmphasis(new SectionEmphasisType('none'));
$columnsHorizontalSectionColumn1 = new HorizontalSectionColumn();
$columnsHorizontalSectionColumn1->setId('1');
$columnsHorizontalSectionColumn1->setWidth(8);
$webpartsWebPart1 = new WebPart();
$webpartsWebPart1->setId('6f9230af-2a98-4952-b205-9ede4f9ef548');
$additionalData = [
'innerHtml' => '<p><b>Hello!</b></p>',
];
$webpartsWebPart1->setAdditionalData($additionalData);
$webpartsArray []= $webpartsWebPart1;
$columnsHorizontalSectionColumn1->setWebparts($webpartsArray);
$columnsArray []= $columnsHorizontalSectionColumn1;
$columnsHorizontalSectionColumn2 = new HorizontalSectionColumn();
$columnsHorizontalSectionColumn2->setId('2');
$columnsHorizontalSectionColumn2->setWidth(4);
$webpartsWebPart1 = new WebPart();
$webpartsWebPart1->setId('73d07dde-3474-4545-badb-f28ba239e0e1');
$additionalData = [
'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',
],
],
],
],
],
];
$webpartsWebPart1->setAdditionalData($additionalData);
$webpartsArray []= $webpartsWebPart1;
$columnsHorizontalSectionColumn2->setWebparts($webpartsArray);
$columnsArray []= $columnsHorizontalSectionColumn2;
$horizontalSectionsHorizontalSection1->setColumns($columnsArray);
$horizontalSectionsArray []= $horizontalSectionsHorizontalSection1;
$canvasLayout->setHorizontalSections($horizontalSectionsArray);
$requestBody->setCanvasLayout($canvasLayout);
$result = $graphServiceClient->sites()->bySiteId('site-id')->pages()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Sites
$params = @{
"@odata.type" = "#microsoft.graph.sitePage"
name = "test.aspx"
title = "test"
pageLayout = "article"
showComments = $true
showRecommendedPages = $false
}
New-MgBetaSitePage -SiteId $siteId -BodyParameter $params
# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = SitePage(
odata_type = "#microsoft.graph.sitePage",
name = "test.aspx",
title = "test",
page_layout = PageLayoutType.Article,
show_comments = True,
show_recommended_pages = False,
title_area = TitleArea(
enable_gradient_effect = True,
image_web_url = "/_LAYOUTS/IMAGES/VISUALTEMPLATETITLEIMAGE.JPG",
layout = TitleAreaLayoutType.ColorBlock,
show_author = True,
show_published_date = False,
show_text_block_above_title = False,
text_above_title = "TEXT ABOVE TITLE",
text_alignment = TitleAreaTextAlignmentType.Left,
additional_data = {
"image_source_type" : 2,
"title" : "sample1",
}
),
canvas_layout = CanvasLayout(
horizontal_sections = [
HorizontalSection(
layout = HorizontalSectionLayoutType.OneThirdRightColumn,
id = "1",
emphasis = SectionEmphasisType.None,
columns = [
HorizontalSectionColumn(
id = "1",
width = 8,
webparts = [
WebPart(
id = "6f9230af-2a98-4952-b205-9ede4f9ef548",
additional_data = {
"inner_html" : "<p><b>Hello!</b></p>",
}
),
]
),
HorizontalSectionColumn(
id = "2",
width = 4,
webparts = [
WebPart(
id = "73d07dde-3474-4545-badb-f28ba239e0e1",
additional_data = {
"web_part_type" : "d1d91016-032f-456d-98a4-721247c305e8",
"data" : (
data_version = "1.9",
description = "Show an image on your page",
title = "Image",
properties = (
image_source_type = 2,
alt_text = "",
overlay_text = "",
siteid = "0264cabe-6b92-450a-b162-b0c3d54fe5e8",
webid = "f3989670-cd37-4514-8ccb-0f7c2cbe5314",
listid = "bdb41041-eb06-474e-ac29-87093386bb14",
uniqueid = "d9f94b40-78ba-48d0-a39f-3cb23c2fe7eb",
img_width = 4288,
img_height = 2848,
fix_aspect_ratio = False,
caption_text = "",
alignment = "Center",
),
server_processed_content = (
image_sources = [
(
key = "imageSource",
value = "/_LAYOUTS/IMAGES/VISUALTEMPLATEIMAGE1.JPG",
),
]
custom_metadata = [
(
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",
),
),
]
),
),
}
),
]
),
]
),
]
),
)
result = await graph_client.sites.by_site_id('site-id').pages.post(body = request_body)