Retrieve Webpart Properties of a SharePoint Page using REST API

In this blog, you will learn how to retrieve the webpart properties from a SharePoint page using REST API.
The page can be accessed using the page relative URL. The following REST API URL can be used to access the webpart properties. 
  1. /_api/web/GetFileByServerRelativeUrl('/Pages/ToolPage4.aspx')/GetLimitedWebPartManager(1)/WebParts?$expand=Webpart  
While using the GetLimitedWebPartManager method, provide the personalization scope to be used in retrieving properties.  The scope can be Shared scope or user specific scope. The scope values are 1 and 0 respectively.
 
$expand is used to expand the properties and it is generally used in REST API calls. Failing to expand the properties, the response will not fetch the webpart property values.
Ajax is used to call the SharePoint API.
 
The following code snippet shows the ajax call to retrieve the webpart properties from SharePoint page. 
  1. $(document).ready(function(){  
  2.     var restURL = "/_api/web/GetFileByServerRelativeUrl('/Pages/ToolPage4.aspx')/GetLimitedWebPartManager(1)/WebParts?$expand=Webpart"  
  3.     $.ajax({  
  4.         url: restURL,  
  5.         method: "GET",  
  6.         headers: { "Accept""application/json; odata=verbose" },  
  7.         async: false,  
  8.         cache: false,  
  9.         success: function (data) {  
  10.         if(data != null && data.d != null){  
  11.         var properties = data.d.results[0]; // Gets First result set  
  12.         var title = data.d.results[0].WebPart.Title; // Gets Title of a webpart  
  13.         }  
  14.     },  
  15.     error: function (data) {  
  16.     }  
  17.     });  
  18.   
  19. });   
The response will be objects (set of webparts) present on the page. The following image shows all the webparts from a page and webpart properties along with Id. If you expand the properties here, you will get more details about the webpart.
 

 
Note: The image shows the response of the above Ajax call on Chrome's debugger.