How To Retrieve Custom Columns For DriveItems in MS Graph

Viewed 3656

I'm trying to use the Graph API to retrieve a hierarchy of files in a Sharepoint document library. Since document libraries are stored in "drives" (is it technically correct to call it OneDrive?), I'm using the /drives endpoint to fetch a list of files, like this:

https://graph.microsoft.com/beta/drives/{driveid}/root/children

I would like to get information from some of the custom columns that exist when viewing these items through Sharepoint. Using ?expand=fields doesn't work because fields only exists in listItem object of the /sites endpoint, not in the driveItem object of /drives endpoint. If I try obtaining the listItem from a single driveItem (traversing the Graph from OneDrive to Sharepoint), and then expanding the fields, like

https://graph.microsoft.com/beta/drives/{driveid}/items/{driveItemId}/listItem?expand=fields

this retrieves built-in columns (Author, DocIcon, and some others) but doesn't seem to retrieve the custom columns. I've also tried getting the list of files from the /sites endpoint, and using ?expand=fields will get the custom columns, but it gets every file from every subfolder, rather than the current folder path. But I feel that deserves its own SO question.

Is it possible to retrieve custom column information from driveItems?

3 Answers

I spent a lot of time digging around with the different syntax possibilities and was finally able to get custom library properties using this query format. This is the only one that has produced my custom/user-defined fields for a document library.

https://graph.microsoft.com/v1.0/drives/insert_drive_id_here/root/children?expand=listItem

Shortened result:

{
"@odata.context": "...",
"value": [
        {
        "@microsoft.graph.downloadUrl": "...",
        "listItem@odata.context": "...",
        "listItem": {
            "@odata.etag": "...",
            "fields@odata.context": "...",
            "fields": {
                "@odata.etag": "...",
                "Title": "...",
                "Other_Custom_Property": "..."
                }
            }
        }
    ]
}
Related