I would like to edit WebParts of a Sharepoint site with Sharepoint REST API. The best option I found so far is to use the GetLimitedWebPartManager method at first to request all WebParts of a site. At the moment Im working with MS PowerAutomate to design this workflow and therefore I request all results of my API-calls as JSON format.
I found this command which should do it:
https://[domain].sharepoint.com/sites/[dev]/_api/web/getFileByServerRelativeUrl('/sites/Example.aspx')/getLimitedWebPartManager(scope=1)/WebParts?$expand=WebPart/Properties
Unfortunately, the response was as following (even tho the site is not empty and has 3 WebParts):
{
"d": {
"results": []
}
}
Also tried something like the following commands, but I think Im still missging something here.
https://[domain].sharepoint.com/sites/[dev]/_api/web/getFileByServerRelativeUrl('/sites/Example.aspx')/getLimitedWebPartManager()/WebParts?$expand=WebPart
https://[domain].sharepoint.com/sites/[dev]/_api/web/getFileByServerRelativeUrl('/sites/Example.aspx')/getLimitedWebPartManager()/WebParts?$select=*&$expand=WebPart
Has anyone an idea what could be causing the empty result?
First of all, I assume you use the modern interface and not the classic one.
As Expiscornovus said you may take a look at the new graph apis related to webparts.
However, this api is limited to some well known webparts.
If you need more control, you can play with the CanvasContent1
field of the page. This field contains a JSON representation of the page, describing the sections and the webparts inside each section.
I saw power-automate
tag in your question. Web build in our company a provisioning software inside power automate. It was a tricky project since power automate is very limited in its apis, and terribly slow. But if it can help, our process to setup pages consists in multiple calls to some apis:
https://tenant.sharepoint.com/sites/somesite/_api/sitepages/pages/GetByUrl('/sites/somesite/sitepages/home.aspx')/checkoutpage
(POST). The result contains the CanvasContent1
fieldhttps://tenant.sharepoint.com/sites/somesite/_api/sitepages/pages/GetByUrl('/sites/somesite/sitepages/home.aspx')/SavePage
, With { "CanvasContent1": "<<encoded json of CanvasContent1>>"}
. Updating the field value didn't worked for using PATCH on the listitem, but this API worked. This is probably the trickiest part.https://tenant.sharepoint.com/sites/somesite/_api/sitepages/pages/GetByUrl('/sites/somesite/sitepages/home.aspx')/publish