SharePoint Online Site Page: Cannot expand canvasLayout on baseSitePage (HTTP status 400)
heinrich-ulbricht opened this issue · 2 comments
What's the goal?
Retrieve a SharePoint Online modern page via Microsoft Graph, using the beta endpoint, using the MS Graph Beta SDK. The page should be returned with content.
How is it failing?
Retrieving a site page (microsoft.graph.sitePage
) via Pages
returns just a base site page (microsoft.graph.baseSitePage
), making it impossible to expand e.g. the canvasLayout
property.
Here's how I'm retrieving the page, trying to expand canvasLayout
:
var sitePage = await graphClient
.Sites[siteId]
.Pages[pageId]
.GetAsync(config =>
{
config.QueryParameters.Expand = new[] { "canvasLayout" };
}) as SitePage;
This throws the exception Parsing OData Select and Expand failed: Could not find a property named 'CanvasLayout' on type 'microsoft.graph.baseSitePage'.
Looking at the generated request I see this:
https://graph.microsoft.com/beta/sites/_siteid_/pages/_pageId_?$expand=canvasLayout
But this should rather be:
https://graph.microsoft.com/beta/sites/_siteid_/pages/_pageId_/microsoft.graph.sitePage?$expand=canvasLayout
How to achieve this, using the Graph Client SDK?
Used for testing:
- latest Graph Beta SDK from Nuget (v5.59.0-preview)
- Windows 11
- .NET 6
One workaround is:
var graphPageRequest = graphClient
.Sites[siteId]
.Pages[pageId]
.ToGetRequestInformation();
graphPageRequest.UrlTemplate = $"{{+baseurl}}/sites/{siteId}/pages/{pageId}/microsoft.graph.sitePage?expand=canvasLayout";
var content = new Microsoft.Graph.BatchRequestContentCollection(graphClient);
var requestStepId = await content.AddBatchRequestStepAsync(graphPageRequest);
var batchResult = await graphClient.Batch.PostAsync(content);
var graphPage = await batchResult.GetResponseByIdAsync<SitePage>(requestStepId);
Note: I did not immediately find how to send the modified graphPageRequest
and the batching approach is the first sample I found that worked. There might be an easier approach.
Depends on microsoftgraph/msgraph-metadata#401