0

I need to write the HTTP query (will call it from a Python script) to get ALL the files (including from all sub-folders of sub-folders) starting from a specific SharePoint Path. I need to run this on a SharePoint 2016 installation.

My Path is something like: https://<my-sharepoint-host>/<subsite>/<library-name>/folder1/sub-folder1

I've been making a lot of attempts around this:

https://<my-sharepoint-host>/<subsite>/_api/web/Lists/GetByTitle('<library-name>')/items?$select=FileLeafRef,File&$expand=File

I could obtain a long list of items (files and folders) with the needed info; below is am extract from such an item:

...
, {
    "odata.type": "SP.Data.EngineeringItem",
    "File": {
        "odata.type": "SP.File",
        "Name": "sample.pptx",
        "ServerRelativeUrl": "<my-sharepoint-host>/<subsite>/<library-name>/some-other-folder-path/.../not-needed.pptx",
    },
    "FileLeafRef": "sample.pptx"
},

...
, {
    "odata.type": "SP.Data.EngineeringItem",
    "File": {
        "odata.type": "SP.File",
        "Name": "sample.pptx",
        "ServerRelativeUrl": "<my-sharepoint-host>/<subsite>/<library-name>/folder1/sub-folder1/needed.docx",
    },
    "FileLeafRef": "sample.pptx"
},

THE PROBLEM is that I cannot filter them more than this. I'm getting the content of the whole library, and I can't figure out how to filter based on the folder path (in my example, folder1/sub-folder1)

How could I do that ?

I tried adding &$filter=... but I could not figure out how to refer to the ServerRelativeUrl field.

Also, where could I find a list of accepted values to use with?$select=... ?

Thank you.

1 Answer 1

1

After some more attempts, I was able to find a solution for this. I'm posting it here in case anybody else runs into anything similar and this helps...

  1. ServerRelativeUrl is what's called a hidden field, so it cannot be used in the filter element.

However...

  1. By Pasting the https://<my-sharepoint-host>/<subsite>/_api/web/Lists/GetByTitle('<library-name>')/fields URL in the browser (as it was suggested to me here), I was able to find the full list of fields available (turned out that the SP installation I have to work with has several customizations...), and I could spot one field called FileRef which worked ok to be used for filtering.

So the final URL that works with a GET operation is https://<my-sharepoint-host>/<subsite>/_api/web/Lists/GetByTitle('<library-name>')/items?$select=File,File/ServerRelativeUrl,FileRef&$expand=File&$filter=startswith(FileRef, '<subsite> + '/' + <library-name> + /folder1/sub-folder1')

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.