SharePoint Online REST APIs (Part IV): Site Collection

Share the love

In the SharePoint Online REST APIs series, I’ll be sharing the most common APIs I use. I mainly use these APIs in Power Automate, so I’ll base the information in this series on the data you need for a Send an HTTP request to SharePoint action.

In this article we are moving away from site content, and exploring how to interact with a SharePoint modern site. This includes site information and how to apply scripts on the site. This is not a comprehensive list; rather a list of calls that I use when I can’t use predefined Power Automate actions. I have used the color red to identify interchangeable values.

Get site information including title

Method

URI

GET

_api/web

This call will return all the site properties including the site ID, site title, site description etc.

Get site logo

Method

URI

GET

_api/web/SiteLogoUrl

This is a handy call if you’re creating an app and want to use the logo that was uploaded on the site.

Get site scripts on site

Method

URI

Body

POST

_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.GetSiteDesignRun

{
'webUrl':'https://tenant.sharepoint.com/sites/Site Name',
'siteDesignId':'GUID'
}

This call will check to see if a specific site script has been deployed to a site. If it is not deployed, it will return nothing. You will need the GUID of the site design.

Get all users on a site

Method

URI

GET

_api/web/SiteUsers?$select=Email&$filter=PrincipalType eq 1

PrincipalType is referring to a user. You can also return distribution lists, SharePoint groups etc. For a list of Principal Types, see this article. In this example, I am selecting the email of all the users. However, you can choose any of the properties that are returned in the _api/web/SiteUsers call.

Using SharePoint search on a site

Method

URI

POST

_api/Search/query?querytext='Search for this'&refinementfilters='ContentType:equals("Item")'&clienttype='ContentSearchRegular'

Sometimes you don’t know where an item resides in a site. It might be in a list, library or it could be a person. This call gives the flexibility of SharePoint search to return search results. In this example, I am searching through all Item Content Types. If an item matches with the search term, ‘Search for this‘, it will be returned in this call. This call is extremely flexible, and is also security trimmed (basically this is the same as a user using a search text box).


Share the love

Leave a Reply

Your email address will not be published. Required fields are marked *