Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharePoint Online Site Page: Cannot expand canvasLayout on baseSitePage (HTTP status 400) #781

Closed
heinrich-ulbricht opened this issue Dec 30, 2023 · 2 comments · Fixed by #787

Comments

@heinrich-ulbricht
Copy link

heinrich-ulbricht commented Dec 30, 2023

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
@heinrich-ulbricht
Copy link
Author

heinrich-ulbricht commented Dec 30, 2023

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.

@andrueastman
Copy link
Member

Depends on microsoftgraph/msgraph-metadata#401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants