Retrieving Custom Columns with File Details using Microsoft Graph API in SharePoint

Almaany, Omar 1 Reputation point
2023-05-23T19:08:01.3633333+00:00

Is it possible to fetch custom columns in conjunction with file details from a SharePoint site using Microsoft Graph APIs? I've been able to retrieve file details successfully but the custom columns aren't being returned in the data.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,869 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-05-29T06:29:51.6533333+00:00

    Hello Almaany, Omar,

    Thanks for reaching out!

    Yes, it is possible to fetch custom columns along with file details from a SharePoint site using Microsoft Graph APIs. When retrieving file details using the Microsoft Graph API, you can include the $expand query parameter to expand the custom columns associated with the file.

    To fetch custom columns, you need to make use of the SharePoint-specific properties. Here's an example API request to retrieve file details along with custom columns:

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}?$expand=fields
    

    In the above request, you need to replace {site-id}, {list-id}, and {item-id} with the actual IDs for your SharePoint site, list, and item respectively. The $expand=fields query parameter is used to include the custom column values associated with the item.

    The response will include the custom column values in the fields property of the item. Each custom column will have its own property within the fields object.

    Make sure that you have the necessary permissions to access the SharePoint site and retrieve custom column data. Additionally, ensure that the custom columns are associated with the list and the items have values for those columns.

    By including the $expand=fields query parameter, you should be able to fetch custom columns along with file details from a SharePoint site using Microsoft Graph APIs.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


  2. Marco Bonalumi 0 Reputation points
    2024-06-28T19:40:49.2633333+00:00

    After struggling for days on this issues at work, i finally found something. I thought I could post my insights here for the world to bump into.

    So, basically when you request for site/{site-id}/pages, you get what microsoft calls baseSitePage in the documentation baseSitePage. If you add /microsoft.graph.sitePage you tell the backend you want entities of the type sitePage.

    The solution the other comment proposes introduces the parameter $expand, which can be done only on those fields that the entity (page, list, user, ...). In case of sitePage, canvasLayout, createdByUser, lastModifiedByUser, webPart. The expand you want to search for is fields though, but that's not available and that's it.

    The good part is that the fields query parameter is requestable for lists or items, as in /sites/{site-id}/lists/{list-id}/items/{item-id}. And there should exist a list (not retrievable through graphapi, as far as I know 😮‍💨) that has all the pages as items, and you can do sites/{site-id}/lists/{list-id}/items?$expand=fields on that list.

    The only workaround I found to get the list-id is to go to a webpage of sharepoint that has all the pages, as a News collection, and in the url get the pagesListId.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.