Graph API : Get Document Library Custom Columns using GraphServiceClient

Soni Samuel Panackacheril 61 Reputation points


I am trying to get Custom Columns in a Sharepoint Online Document Library using GraphService Client.

I am able to get the Files in a Drive (Document Library) using the above approach after creating an IConfidentialClientApplication and getting the Access Token. Even the default columns are not being fetched when I pass the queryOptions into the Request.

var site = await graphServiceClient.Sites[$"{SiteId}"].Request().GetAsync();
var queryOptions = new List<QueryOption>()
new QueryOption("expand", "fields(select=Id,Name)")
var driveItems = await graphServiceClient.Sites[site.Id].Drives[$"{DocLibraryId}"]

Appreciate some feedback on this.


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,839 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,868 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,696 Reputation points Microsoft Vendor

    Hi @Soni Samuel Panackacheril ,

    Driveitem doesn't have fields relationship only listItem has.
    You can use driveitem relationship listItem this example will get drives root children listitem.

    GET /sites/{siteId}/drives/{driveId}/root/children?$expand=listItem

    Your Graph SDK code would look as below,

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
    var children = await graphClient.Sites[{siteId}].Drives[{driveId}].Root.Children  

    To get a driveItems column metadata properties GET /sites/{siteId}/drives/{driveId}/items/{driveItemId}/listItem.

    Also, additionally we can use Sites-Lists to get column values of document library, please note that driveId and listIdOfDocLibr will be different.

    GET /sites/{siteId}/lists/{listIdOfDocLib}/items?$expand=fields


    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.