node.jssharepointmicrosoft-graph-apisharepoint-api

Find or expand Sharepoint Page titleArea image - Microsoft Graph API


I have been struggling in the past days trying to find an related article/documentation about the Sharepoint Graph API site page image which is inside the titleArea or thumbnailWebUrl.

There is no proper documentation how to achieve this, there are many subfolders being created where the images get stored into the "Site Assets" or more preferably inside Site Contents - there are many subfolders and it's never accurate to properly automate this for each page that are stored inside a site, has anyone achieved this matter to retrieve an public CDN url for the images?

I am using OAuth granted generated tokens with offline access and scopes: Sites.ReadWrite.All Files.Read.All

I have tried many ways like:


Solution

  • I would retrieve all SharePoint lists including the hidden one to find out the id of Site Assets list

    GET /v1.0/sites/{site_id}/lists?$select=id,displayName,description,system
    

    One of the returned list should have the displayName like Site Assets (or localized name). Use the list id in the next request to find out the drive related to Site Assets list

    GET /v1.0/sites/{site_id}/lists/{site_assets_list_id}/drive
    

    Now, use driveId and rest of the URL after SiteAssets in thumbnailWebUrl

    /sites/mypersonalsite/SiteAssets/SitePages/1g33v8at/77787-Copy-of-Header-Vorlage--6-.png

    =>

    SitePages/1g33v8at/77787-Copy-of-Header-Vorlage--6-.png as a relative path to get driveItem related to the image in the title area.

    GET /v1.0/drives/{drive_id}/root:/{relative_path}:/
    GET /v1.0/drives/{drive_id}/root:/SitePages/1g33v8at/77787-Copy-of-Header-Vorlage--6-.png:/