I need to determine the type of a web part (eg. Script Editor, Search Results, etc.) on pages using JavaScript.
I started with REST and succeeded in getting the web part manager for a page and got the web part definitions (SP.WebParts.WebPartDefinition
) as well. Unfortunately there is no type information, only Title
, TitleUrl
, ZoneIndex
, Id
etc. There is also no Properties
property which I saw in some samples.
My request looks like this:
https://siteUrl/_api/web/getFileByServerRelativeUrl(fileUrl)/getLimitedWebPartManager(scope=1)/webparts?$expand=Webpart
I'm interested in SharePoint 2013 and 2016. I read about an ExportWebpart
API which was introduced in 2016 for SP Online which seems to be missing at least on my on-prem test farm. If there are any means for on-prem I'd also like to know any patch level needed for the API to be available. But I could probably google this myself once I know the API.
So how do I get the type of a web part using JavaScript and REST (or JSOM - maybe there are more possibilities?) for SP on-prem?
More information
When exporting the web part manually in the browser UI I get the information I need - in two places of the exported web part XML:
Metadata of the exported web part (This is what I'd like to have!):
<metaData>
<type name="Microsoft.SharePoint.WebPartPages.ClientWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
As an alternative (workaround) the properties would be (maybe) sufficient for my case as well. I could identify the web parts I'm interested in via their unique combination of properties like the FeatureId and others:
<property name="FeatureId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">GUID I can use</property>
But I just cannot get these properties as well, using REST.
I checked that the export mode allows exporting the data:
That the web part properties are retrievable via Remote API:
I tried expanding WebPart.Properties
instead of WebPart
(like in some JSOM samples).
Nope. Maybe it's just not possible via REST? The documentation is no reason to party either.