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

nicholas dipiazza 26 Reputation points
2021-06-30T18:32:12.377+00:00

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?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,677 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,969 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,031 Reputation points
    2021-07-01T06:08:49.333+00:00

    Hi @nicholas dipiazza ,

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.