question

nicholasdipiazza-9485 avatar image
0 Votes"
nicholasdipiazza-9485 asked MichaelHan-MSFT edited

How do you download the actual HTML content of a SharePoint Online page using OAuth credentials (Bearer token)?



How do you download the actual HTML content of a SharePoint Online page using OAuth credentials (Bearer token)?

I want to download the HTML content from here: https://mytenant.sharepoint.com/sites/theSiteHere/

You get a 401 Unauthorized if you try to HTTP Get this URL using a bearer token.

To download files from sharepoint using a bearer token, you must make requests like this:

https://mytenant.sharepoint.com/sites/theSiteHere/_api/Web/getfilebyserverrelativeurl('/sites/theSiteHere/SitePages/Home.aspx')/$value

The results in garbage asp.net code that does not have my HTML content.

<%@ Assembly Name="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%> <%@ Page Language="C#" Inherits="Microsoft.SharePoint.WebControls.ClientSidePage" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head>
<!--[if gte mso 9]><SharePoint:CTFieldRefs runat=server Prefix="mso:" FieldList="FileLeafRef,ClientSideApplicationId,PageLayoutType,CanvasContent1,BannerImageUrl,BannerImageOffset,PromotedState,FirstPublishedDate,LayoutWebpartsContent,_TopicHeader,_SPSitePageFlags,_SPAssetFolderId"><xml>
<mso:CustomDocumentProperties>
<mso:PageLayoutType msdt:dt="string">Home</mso:PageLayoutType>
<mso:ClientSideApplicationId msdt:dt="string">B6917CB1-93A0-4B97-A84D-7CF49975D4EC</mso:ClientSideApplicationId>
<mso:ContentTypeId msdt:dt="string">0x0101009D1CB255DA76424F860D91F20E6C4118</mso:ContentTypeId>
</mso:CustomDocumentProperties>
</xml></SharePoint:CTFieldRefs><![endif]-->
<title>Home</title></head>

What is the correct way to actually download the rendered HTML from this page using a bearer token?

office-sharepoint-onlinesharepoint-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @nicholasdipiazza-9485 ,

No, we can not download the HTML of SharePoint page using bearer token.

In SharePoint Online, pages are aspx file that includes the asp:content elements. When using bearer token to download the page content, we can only get asp.net code instead of HTML for the file.

To download the rendered HTML from this page, you have to use browser to open the page, then sace the page as html file.


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@nicholasdipiazza-9485 ,
How are things going? Is there any update on your issue?
I am willing to hear from you. If an Answer is helpful, please click "Accept Answer" and upvote it.

0 Votes 0 ·