Forum Discussion
Using the REST API to export page layout and web parts to site script
Hey kenneho ,
I would suggest you to use the https://github.com/SharePoint/PnP-PowerShell to create site templates. I'd say that's the recomended approach, as it's been monthly updated by Microsoft and it's open source. You can use the command https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnpprovisioningtemplate?view=sharepoint-ps to generate a file(preferrably xml) containing the site template. From there you can use the command https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/apply-pnpprovisioningtemplate?view=sharepoint-ps to apply the generated template to another site. Although this feature is pretty reliable, you may run into some issues trying to "duplicate" the site without modifying a few lines of code(that was my experience, at least). But in the long run I'd say it is worth it. Let me know if you need any help.
Thanks for your input, Carlos_Marins.
For different reasons I'm using Python instead of Powershell, so I need to find a way to convert your proposed solution over to Python. I'm thinking that the PnP Powershell module likely is talking to the Sharepoint Online's REST or Graph endpoint, so if I can figure out which endpoints there are, I can have my Python code use those endpoints as well. You wouldn't happen to have an idea which REST API endpoint may be involved here?
By the way, I just came across this information from https://support.office.com/en-us/article/create-and-use-site-templates-in-sharepoint-server-versions-60371b0f-00e0-4c49-a844-34759ebdd989?ui=en-US&rs=en-US&ad=US: "The Save site as template option is not supported in SharePoint Server 2019 (modern sites) or SharePoint Online (modern sites)". As I'm using SharePoint Online to create modern sites, maybe working with site templates is a lost case from the get-go. Have you succeeded in creating site templates from SharePoint Online modern sites?
- Carlos_MarinsNov 27, 2019Iron Contributor
Hey kenneho,
Oh, I don't know if you can really do it using Python. The PnP PowerShell Module uses CSOM AFAIK so not all features available could be translated to REST, although I believe many of them are. Do you have an exact set of features that you need for your site? We can look up if they are available through REST if you do.
About the link with site templates, yeah i have seen that before. It was kind of useful for classic sites, but not for Modern ones.