Forum Discussion

Christopher Johnson's avatar
Christopher Johnson
Brass Contributor
Jun 14, 2017

Access denied in SharePoint SitePages library

I am trying to create modern SharePoint pages programmatically in SitePages libraries on groups-based sites.

 

I first attempted doing so with PowerShell, then with Flow and finally confirmed via a direct call to the REST service that it is not supported-- in each case, the result is the same: Access Denied.

 

Is there a policy on modern SharePoint SitePages libraries that prevents users-- even users with full control of the site-- from creating content via REST?

 

Below is the result of the REST post to /files/add method:

{ "status": 403, "message": "Access denied. You do not have permission to perform this action or access this resource.", "source": "https://<myTenantUrl>.sharepoint.com/sites/<siteName>/_api/web/GetFolderByServerRelativeUrl('/sites/Safety/SitePages')/files/add(url='Test9.aspx',%20overwrite='true')", "errors": [ "-2147024891", "System.UnauthorizedAccessException" ] }

"-2147024891", "System.UnauthorizedAccessException" ] }

 

This appears related to https://github.com/SharePoint/PnP-PowerShell/issues/819#issuecomment-295660778, in which the same occurs when attempting to upload a page via PowerShell.

 

Per this post by Vesa Juvonen, the https://msdn.microsoft.com/en-us/pnp_articles/modern-experience-customizations-customize-pagesand there are PnP extension methods to do so. 

 

TL;DR: Just want to confirm that the same is NOT possible via REST at this time as it will affect the architecture of a solution I'm writing.

 

10 Replies

  • Jonathan Cardy's avatar
    Jonathan Cardy
    Copper Contributor

    Trying to upload an aspx file directly will raise the Access Denied error, but you can use the `Files.AddTemplateFile` method do it: https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/modern-experience-customizations-customize-pages

  • Just tried this on my tenant, I can upload via REST to Site Pages on classic sites, I get the same behaviour as you describe when trying on a Modern site.

    • Christopher Johnson's avatar
      Christopher Johnson
      Brass Contributor
      Thanks for double-checking me. One comment on my PnP query suggested that this is intentional to prevent developers from uploading ASPX pages. Not sure if this is the case or not; hoping we can get some kind of confirmation from Microsoft.
      • Marc Vanderstraeten's avatar
        Marc Vanderstraeten
        Brass Contributor

        I had the same issue trying with CSOM... Any solution?

        What I saw in the permissions is that there is a DENY ... Another indicator that something is blocking us...


        Deny

Resources