0

I'd like a Power Automate flow to configure read permissions on the Site Assets library for a SharePoint group that contains external users.

However, I'm having a hard time retrieving the Site Assets library through the SharePoint REST API. This morning I observed some interesting behavior.

When a new team site has been created, and run the following query, I get no results: GET https://tenantname.sharepoint.com/sites/2023-00719/_api/web/lists?$filter=Title eq 'Siteactiva' (where Siteactiva equals Site Assets in Dutch).

Even when I paste the request URL in the browser, it returns an empty array.

However, when I visit the site through the browser, walk through the site templates pop-up and then run the same query once again I do get the list returned. Nothing changed to the request URL.

What would be the best approach for me to retrieve the Site Assets library's GUID after the team site has just been created?

Thanks in advance for all help provided!

1 Answer 1

2

We can't use ID (GUID) of the site asset library because it will be different for each site.

You can use below query (Considering that you do have site always with same as Base Language - as per your requirement in Dutch) to get site assets library by Title:

{SiteUrl}/_api/web/lists/getbytitle('{Site Assets Library title in Dutch Langauge}')

If your site can be with different base language then Title can be different and in that case you can use below query to use it by URL instead of Title because URL would be always same of the Site Assets library in all language sites:

{SiteUrl}/_api/web/getlist('{SiteRelUrl}/SiteAssets')

E.g. If your site url is https://contoso.sharepoint.com/sites/testsite then api call would be

https://contoso.sharepoint.com/sites/testsite/_api/web/getlist('/sites/testsite/siteassets')

Read more about REST API in SharePoint at below link:

Complete basic operations using SharePoint REST endpoints

Update

If seems that you are trying to access site after creating it directly and by default Site Assets library is not created and it will be created when you access site first time in browser. In order ensure site assess library without accessing site in browser you can use EnsureSiteAssetsLibrary API. Following is the API Details:

API URL: {SiteURL}/_api/web/Lists/EnsureSiteAssetsLibrary/
API Type: POST
API Headers: "Accept" = "application/json;odata=nometadata"

Reference Link:

Ensure the Site Assets Library is created

4
  • Hi Kalpesh, thank you for your reply. I know the GUID will be different for each site. However, the queries you have suggested do not seem to work. Each time I am getting a HTTP 404 'file not found' response from the SharePoint REST API. The team site that I have created is in the default language of Dutch (Site settings -> Language settings). However, when I navigate to the site using a browser, skip the site templates prompt, and perform the REST API query getlist('sites/testsite/siteassets') again... then it does work. Something seems to change or provision upon accessing the site. Commented May 2, 2023 at 8:25
  • so are you creating site first and then trying to get site assets library? Commented May 2, 2023 at 8:39
  • I have updated my answer accordingly. Please try EnsureSiteAssetsLibrary api because accessing Site Assets library using REST API. Let me know whether it works for you or not Commented May 2, 2023 at 8:51
  • Thank you Kalpesh, I wasn't aware of this function. It indeed works fine and now I have consistent behavior. Commented May 2, 2023 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.