3

I am currently trying to get the whole content of a modern SharePoint page using either API but I am not retrieving it successfully. So far I have tried the following:

  • Calling https://xxxx.sharepoint.com/sites/{mysite}/_api/Web/lists/getbytitle('Site Pages')/items(x)/FieldValuesAsHtml

Doing so depending on the page I manage to get some content in the CanvasContent1 field. But unless it is an old SharePoint page or a plain looking one, I get no relevant content here.

  • Calling https://xxxx.sharepoint.com/sites/{mysite}/_api/Web/lists/getbytitle('Site Pages')/items(x)/FieldValuesAsText

Same thing as before, although whenever I get useful information, it looks better here than with FieldValuesAsHtml, again in the field CanvasContent1.

  • Attempting it with the GraphAPI calling https://graph.microsoft.com/beta/sites/{mysiteid}/pages/{mypageid}/webparts

When doing this only 2 fields are received: @odata.context which contains a URL with an XML which doesn't solve anything for me and value which is always blank"[]" for me.

  • Also tried https://graph.microsoft.com/beta/sites/{mysiteid}/pages/{mypageid}?expand=canvasLayout but I am only getting something relevant in the description field and that is not the whole page.

I am trying all of this with Postman, I don't know if this might be relevant.

TLDR: What is the proper way of getting the whole content of a modern SharePoint page using either SharePoint API or Microsoft Graph API. Getting it as text/xml/html I do not care, any one works for me.

2
  • do you want to get only content (from text web parts) or you want also other information like other web part along with it's configuration? Commented May 3, 2023 at 8:29
  • I am only interested in content. Any text that is displayed in the page.
    – Smock
    Commented May 3, 2023 at 8:43

2 Answers 2

0

You can try using below SharePoint REST API endpoint:

Using item ID:

https://contoso.sharepoint.com/sites/SiteName/_api/web/lists/getbytitle('Site Pages')/items(1)?$select=Title,CanvasContent1

Using page name:

https://contoso.sharepoint.com/sites/SiteName/_api/web/lists/getbytitle('Site Pages')/items?$select=Title,FileLeafRef,CanvasContent1&$filter=FileLeafRef eq 'Employee.aspx'

Similar thread: need to read metadata from sharePoint is anyone help me

2
  • Like I said, this solution works only for simple pages that have plain text. On modern pages that have diferent boxes with information, other titles, or something more complicated, I get null in CanvasContent1 if there is no plain text.
    – Smock
    Commented May 3, 2023 at 10:00
  • @Smock Did you ever manage to solve it? Commented Mar 27 at 16:15
0

I don't know if this is still relevant, but i tested it with the expand attribute. It works on my deployment (sharepoint online):

https://graph.microsoft.com/beta/sites/<<SITE-ID>>/pages/<<PAGE-ID>>/microsoft.graph.sitePage?$expand=canvasLayout

See this: https://learn.microsoft.com/en-us/graph/api/sitepage-get?view=graph-rest-1.0&tabs=http#example-3-get-a-page-with-page-content

Regards

Hannes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.