Search code examples
sharepointfetch-apisharepoint-rest-api

Get the preview URL in SharePoint Document library via REST API


I am making a custom web part that connects to the Documents list on SharePoint via Fetch. This is the call that I use for retrieving information:

/_api/web/lists/getByTitle('Documents')/items?$select=EncodedAbsUrl,*,File/Name&$expand=Folder&$expand=File

Right now I get mostly all the data that I need for all the items, but I just need to also have the URL that redirects you to the preview of the file Example of file preview

If possible, I don't want to make another fetch, So is there any item property that I could expand to get the preview URL, via REST API?

I checked the values of EncodedAbsUrl and ServerRedirectedEmbedUrl, but these are not exactly the preview URL that I have in mind.

I've seen a similar question to mine, even tho I don't need the same thing I've also tried expanding the fetch to recieve more data of vti_x005f but still, I couldn't find the preview URL

Similar Question

With this one: /_api/web/lists/getByTitle('Documents')/items?$select=EncodedAbsUrl,*,File/Name/Properties/vti_x005f_shortcuturl&$expand=Folder&$expand=File&$expand=Properties

Thank you in advance,


Solution

  •  /_api/web/lists/getbytitle('Documents')/items?$select=*,FileLeafRef,FileRef
    

    then use for pdf or word

    absoluteUrl + "/_layouts/15/WopiFrame.aspx?sourcedoc=" + FileRef + "&file=" +FileLeafRef + "&action=default"
    

    for images

    /sites/Development/Shared%20Documents/Forms/AllItems.aspx?id=/sites/Development/Shared Documents/lehladakh.jpg&parent=/sites/Development/Shared Documents