How To Retrieve Custom Columns For DriveItems in MS Graph

风格不统一 提交于 2019-12-08 08:01:58

问题


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?


回答1:


I did some testing. What SHOULD work is:

https://graph.microsoft.com/beta/drives/{driveid}/root/children?$select=id,MyCustomColumnName

However, when I did that, it just returned that id field. In my opinion, that is a bug in the graph because this same type of query does work in the SharePoint REST api.

If this helps, you can accomplish this by using the SharePoint REST api. Your endpoint query would be something like:

https://{yoursite}.sharepoint.com/sites/{sitename}/_api/web/lists/(' {DocumentLibraryID}')/items?$select=id,MyCustomColumnName

There are other ways to do the same query.




回答2:


Try the list endpoint then expand driveItem and fields. You now have both custom column fields and drive item fields.

 /beta/sites/[site-id]/lists/[list-id]/items?expand=driveitem,fields&filter=(fields/customColumn eq 'someValue') 


来源:https://stackoverflow.com/questions/44166662/how-to-retrieve-custom-columns-for-driveitems-in-ms-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!