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
{
"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
{
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<>
{
new
{
Key = "imageSource",
Value = "/_LAYOUTS/IMAGES/VISUALTEMPLATEIMAGE1.JPG",
},
},
CustomMetadata = new List<>
{
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);
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewSitePage()
name := "test.aspx"
requestBody.SetName(&name)
title := "test"
requestBody.SetTitle(&title)
pageLayout := graphmodels.ARTICLE_PAGELAYOUTTYPE
requestBody.SetPageLayout(&pageLayout)
showComments := true
requestBody.SetShowComments(&showComments)
showRecommendedPages := false
requestBody.SetShowRecommendedPages(&showRecommendedPages)
titleArea := graphmodels.NewTitleArea()
enableGradientEffect := true
titleArea.SetEnableGradientEffect(&enableGradientEffect)
imageWebUrl := "/_LAYOUTS/IMAGES/VISUALTEMPLATETITLEIMAGE.JPG"
titleArea.SetImageWebUrl(&imageWebUrl)
layout := graphmodels.COLORBLOCK_TITLEAREALAYOUTTYPE
titleArea.SetLayout(&layout)
showAuthor := true
titleArea.SetShowAuthor(&showAuthor)
showPublishedDate := false
titleArea.SetShowPublishedDate(&showPublishedDate)
showTextBlockAboveTitle := false
titleArea.SetShowTextBlockAboveTitle(&showTextBlockAboveTitle)
textAboveTitle := "TEXT ABOVE TITLE"
titleArea.SetTextAboveTitle(&textAboveTitle)
textAlignment := graphmodels.LEFT_TITLEAREATEXTALIGNMENTTYPE
titleArea.SetTextAlignment(&textAlignment)
additionalData := map[string]interface{}{
"imageSourceType" : int32(2) ,
"title" : "sample1",
}
titleArea.SetAdditionalData(additionalData)
requestBody.SetTitleArea(titleArea)
canvasLayout := graphmodels.NewCanvasLayout()
horizontalSection := graphmodels.NewHorizontalSection()
layout := graphmodels.ONETHIRDRIGHTCOLUMN_HORIZONTALSECTIONLAYOUTTYPE
horizontalSection.SetLayout(&layout)
id := "1"
horizontalSection.SetId(&id)
emphasis := graphmodels.NONE_SECTIONEMPHASISTYPE
horizontalSection.SetEmphasis(&emphasis)
horizontalSectionColumn := graphmodels.NewHorizontalSectionColumn()
id := "1"
horizontalSectionColumn.SetId(&id)
width := int32(8)
horizontalSectionColumn.SetWidth(&width)
webPart := graphmodels.NewWebPart()
id := "6f9230af-2a98-4952-b205-9ede4f9ef548"
webPart.SetId(&id)
additionalData := map[string]interface{}{
"innerHtml" : "<p><b>Hello!</b></p>",
}
webPart.SetAdditionalData(additionalData)
webparts := []graphmodels.WebPartable {
webPart,
}
horizontalSectionColumn.SetWebparts(webparts)
horizontalSectionColumn1 := graphmodels.NewHorizontalSectionColumn()
id := "2"
horizontalSectionColumn1.SetId(&id)
width := int32(4)
horizontalSectionColumn1.SetWidth(&width)
webPart := graphmodels.NewWebPart()
id := "73d07dde-3474-4545-badb-f28ba239e0e1"
webPart.SetId(&id)
additionalData := map[string]interface{}{
"webPartType" : "d1d91016-032f-456d-98a4-721247c305e8",
data := graphmodels.New()
dataVersion := "1.9"
data.SetDataVersion(&dataVersion)
description := "Show an image on your page"
data.SetDescription(&description)
title := "Image"
data.SetTitle(&title)
properties := graphmodels.New()
imageSourceType := int32(2)
properties.SetImageSourceType(&imageSourceType)
altText := ""
properties.SetAltText(&altText)
overlayText := ""
properties.SetOverlayText(&overlayText)
siteid := "0264cabe-6b92-450a-b162-b0c3d54fe5e8"
properties.SetSiteid(&siteid)
webid := "f3989670-cd37-4514-8ccb-0f7c2cbe5314"
properties.SetWebid(&webid)
listid := "bdb41041-eb06-474e-ac29-87093386bb14"
properties.SetListid(&listid)
uniqueid := "d9f94b40-78ba-48d0-a39f-3cb23c2fe7eb"
properties.SetUniqueid(&uniqueid)
imgWidth := int32(4288)
properties.SetImgWidth(&imgWidth)
imgHeight := int32(2848)
properties.SetImgHeight(&imgHeight)
fixAspectRatio := false
properties.SetFixAspectRatio(&fixAspectRatio)
captionText := ""
properties.SetCaptionText(&captionText)
alignment := "Center"
properties.SetAlignment(&alignment)
data.SetProperties(properties)
serverProcessedContent := graphmodels.New()
:= graphmodels.New()
key := "imageSource"
.SetKey(&key)
value := "/_LAYOUTS/IMAGES/VISUALTEMPLATEIMAGE1.JPG"
.SetValue(&value)
imageSources := []graphmodels.Objectable {
,
}
serverProcessedContent.SetImageSources(imageSources)
:= graphmodels.New()
key := "imageSource"
.SetKey(&key)
value := graphmodels.New()
siteid := "0264cabe-6b92-450a-b162-b0c3d54fe5e8"
value.SetSiteid(&siteid)
webid := "f3989670-cd37-4514-8ccb-0f7c2cbe5314"
value.SetWebid(&webid)
listid := "bdb41041-eb06-474e-ac29-87093386bb14"
value.SetListid(&listid)
uniqueid := "d9f94b40-78ba-48d0-a39f-3cb23c2fe7eb"
value.SetUniqueid(&uniqueid)
width := "4288"
value.SetWidth(&width)
height := "2848"
value.SetHeight(&height)
.SetValue(value)
customMetadata := []graphmodels.Objectable {
,
}
serverProcessedContent.SetCustomMetadata(customMetadata)
data.SetServerProcessedContent(serverProcessedContent)
webPart.SetData(data)
}
webPart.SetAdditionalData(additionalData)
webparts := []graphmodels.WebPartable {
webPart,
}
horizontalSectionColumn1.SetWebparts(webparts)
columns := []graphmodels.HorizontalSectionColumnable {
horizontalSectionColumn,
horizontalSectionColumn1,
}
horizontalSection.SetColumns(columns)
horizontalSections := []graphmodels.HorizontalSectionable {
horizontalSection,
}
canvasLayout.SetHorizontalSections(horizontalSections)
requestBody.SetCanvasLayout(canvasLayout)
result, err := graphClient.Sites().BySiteId("site-id").Pages().Post(context.Background(), requestBody, nil)
const options = {
authProvider,
};
const client = Client.init(options);
const 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(sitePage);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new 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' => $webpartsWebPart1 = new Data();
$ webpartsWebPart1->setDataVersion('1.9');
$ webpartsWebPart1->setDescription('Show an image on your page');
$ webpartsWebPart1->setTitle('Image');
$properties = new Properties();
$properties->setImageSourceType(2);
$ properties->setAltText('');
$ properties->setOverlayText('');
$ properties->setSiteid('0264cabe-6b92-450a-b162-b0c3d54fe5e8');
$ properties->setWebid('f3989670-cd37-4514-8ccb-0f7c2cbe5314');
$ properties->setListid('bdb41041-eb06-474e-ac29-87093386bb14');
$ properties->setUniqueid('d9f94b40-78ba-48d0-a39f-3cb23c2fe7eb');
$properties->setImgWidth(4288);
$properties->setImgHeight(2848);
$properties->setFixAspectRatio(false);
$ properties->setCaptionText('');
$ properties->setAlignment('Center');
$webpartsWebPart1->setProperties($properties);
$serverProcessedContent = new ServerProcessedContent();
$imageSources1 = new ();
$ imageSources1->setKey('imageSource');
$ imageSources1->setValue('/_LAYOUTS/IMAGES/VISUALTEMPLATEIMAGE1.JPG');
$imageSourcesArray []= $imageSources1;
$serverProcessedContent->setImageSources($imageSourcesArray);
$customMetadata1 = new ();
$customMetadata1->setKey('imageSource');
$customMetadata1Value = new Value();
$customMetadata1Value->setSiteid('0264cabe-6b92-450a-b162-b0c3d54fe5e8');
$customMetadata1Value->setWebid('f3989670-cd37-4514-8ccb-0f7c2cbe5314');
$customMetadata1Value->setListid('bdb41041-eb06-474e-ac29-87093386bb14');
$customMetadata1Value->setUniqueid('d9f94b40-78ba-48d0-a39f-3cb23c2fe7eb');
$customMetadata1Value->setWidth('4288');
$customMetadata1Value->setHeight('2848');
$customMetadata1->setValue($customMetadata1Value);
$customMetadataArray []= $customMetadata1;
$serverProcessedContent->setCustomMetadata($customMetadataArray);
$webpartsWebPart1->setServerProcessedContent($serverProcessedContent);
$webpartsWebPart1->setData($data);
];
$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);
Import-Module Microsoft.Graph.Sites
$params = @{
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 =
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"
}
)
}
)
}
)
}
}
New-MgSitePage -SiteId $siteId -BodyParameter $params