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

%3CLINGO-SUB%20id%3D%22lingo-sub-2503231%22%20slang%3D%22en-US%22%3EHow%20do%20you%20download%20the%20actual%20HTML%20content%20of%20a%20SharePoint%20Online%20page%20using%20OAuth%20credentials%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2503231%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22s-prose%20js-post-body%22%3E%3CP%3EHow%20do%20you%20download%20the%20actual%20HTML%20content%20of%20a%20SharePoint%20Online%20page%20using%20OAuth%20credentials%20(Bearer%20token)%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20download%20the%20HTML%20content%20from%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2FtheSiteHere%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2FtheSiteHere%2F%3C%2FA%3E%3C%2FP%3E%3CP%3EYou%20get%20a%20401%20Unauthorized%20if%20you%20try%20to%20HTTP%20Get%20this%20URL%20using%20a%20bearer%20token.%3C%2FP%3E%3CP%3ETo%20download%20files%20from%20sharepoint%20using%20a%20bearer%20token%2C%20you%20must%20make%20requests%20like%20this%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2FtheSiteHere%2F_api%2FWeb%2Fgetfilebyserverrelativeurl('%2Fsites%2FtheSiteHere%2FSitePages%2FHome.aspx')%2F%24value%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2FtheSiteHere%2F_api%2FWeb%2Fgetfilebyserverrelativeurl('%2Fsites%2FtheSiteHere%2FSitePages%2FHome.aspx')%2F%24value%3C%2FA%3E%3C%2FP%3E%3CP%3EThe%20results%20in%20garbage%20asp.net%20code%20that%20does%20not%20have%20my%20HTML%20content.%3C%2FP%3E%3CPRE%3E%26lt%3B%25%40%20Assembly%20Name%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint%2C%20Version%3D16.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D71e9bce111e9429c%22%3C%2FSPAN%3E%25%26gt%3B%20%26lt%3B%25%40%20Page%20Language%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22C%23%22%3C%2FSPAN%3E%20Inherits%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint.WebControls.ClientSidePage%22%3C%2FSPAN%3E%20%20%20%20%20%20%20%25%26gt%3B%20%26lt%3B%25%40%20Import%20Namespace%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint%22%3C%2FSPAN%3E%20%25%26gt%3B%20%26lt%3B%25%40%20Register%20Tagprefix%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22SharePoint%22%3C%2FSPAN%3E%20Namespace%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint.WebControls%22%3C%2FSPAN%3E%20Assembly%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint%2C%20Version%3D16.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D71e9bce111e9429c%22%3C%2FSPAN%3E%20%25%26gt%3B%20%26lt%3B%25%40%20Register%20Tagprefix%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Utilities%22%3C%2FSPAN%3E%20Namespace%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint.Utilities%22%3C%2FSPAN%3E%20Assembly%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint%2C%20Version%3D16.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D71e9bce111e9429c%22%3C%2FSPAN%3E%20%25%26gt%3B%20%26lt%3B%25%40%20Import%20Namespace%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.SharePoint%22%3C%2FSPAN%3E%20%25%26gt%3B%20%26lt%3B%25%40%20Assembly%20Name%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22Microsoft.Web.CommandUI%2C%20Version%3D16.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D71e9bce111e9429c%22%3C%2FSPAN%3E%20%25%26gt%3B%0A%3CSPAN%20class%3D%22hljs-attribute%22%3Exmlns%3C%2FSPAN%3E%3Amso%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22urn%3Aschemas-microsoft-com%3Aoffice%3Aoffice%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-attribute%22%3Exmlns%3C%2FSPAN%3E%3Amsdt%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22uuid%3AC2F41010-65B3-11d1-A29F-00AA00C14882%22%3C%2FSPAN%3E%26gt%3B%0A%3C!--%5Bif%20gte%20mso%20%3CSPAN%20class%3D%22hljs-number%22--%3E9%5D%26gt%3B%26lt%3B%3CSPAN%20class%3D%22hljs-attribute%22%3ESharePoint%3C%2FSPAN%3E%3ACTFieldRefs%20runat%3Dserver%20Prefix%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22mso%3A%22%3C%2FSPAN%3E%20FieldList%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22FileLeafRef%2CClientSideApplicationId%2CPageLayoutType%2CCanvasContent1%2CBannerImageUrl%2CBannerImageOffset%2CPromotedState%2CFirstPublishedDate%2CLayoutWebpartsContent%2C_TopicHeader%2C_SPSitePageFlags%2C_SPAssetFolderId%22%3C%2FSPAN%3E%26gt%3B%3CXML%3E%0A%26lt%3B%3CSPAN%20class%3D%22hljs-attribute%22%3Emso%3C%2FSPAN%3E%3ACustomDocumentProperties%26gt%3B%0A%26lt%3B%3CSPAN%20class%3D%22hljs-attribute%22%3Emso%3C%2FSPAN%3E%3APageLayoutType%20%3CSPAN%20class%3D%22hljs-attribute%22%3Emsdt%3C%2FSPAN%3E%3Adt%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22string%22%3C%2FSPAN%3E%26gt%3BHomemso%3APageLayoutType%26gt%3B%0A%26lt%3B%3CSPAN%20class%3D%22hljs-attribute%22%3Emso%3C%2FSPAN%3E%3AClientSideApplicationId%20%3CSPAN%20class%3D%22hljs-attribute%22%3Emsdt%3C%2FSPAN%3E%3Adt%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22string%22%3C%2FSPAN%3E%26gt%3BB6917CB1-%3CSPAN%20class%3D%22hljs-number%22%3E93%3C%2FSPAN%3EA0-%3CSPAN%20class%3D%22hljs-number%22%3E4%3C%2FSPAN%3EB97-A84D-%3CSPAN%20class%3D%22hljs-number%22%3E7%3C%2FSPAN%3ECF49975D4ECmso%3AClientSideApplicationId%26gt%3B%0A%26lt%3B%3CSPAN%20class%3D%22hljs-attribute%22%3Emso%3C%2FSPAN%3E%3AContentTypeId%20%3CSPAN%20class%3D%22hljs-attribute%22%3Emsdt%3C%2FSPAN%3E%3Adt%3D%3CSPAN%20class%3D%22hljs-string%22%3E%22string%22%3C%2FSPAN%3E%26gt%3B%3CSPAN%20class%3D%22hljs-number%22%3E0%3C%2FSPAN%3Ex0101009D1CB255DA76424F860D91F20E6C4118mso%3AContentTypeId%26gt%3B%0Amso%3ACustomDocumentProperties%26gt%3B%0A%3C%2FXML%3ESharePoint%3ACTFieldRefs%26gt%3B%26lt%3B!%5Bendif%5D--%26gt%3B%0A%26lt%3Btitle%26gt%3BHome%26lt%3B%2Ftitle%26gt%3B%26lt%3B%2Fhead%26gt%3B%3C%2FPRE%3E%3CP%3EWhat%20is%20the%20correct%20way%20to%20actually%20download%20the%20rendered%20HTML%20from%20this%20page%20using%20a%20bearer%20token%3F%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2503231%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

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?

0 Replies