SharePoint Online Access List Item by ID using Graph API


In this page, we will see How to access SharePoint Online List Item by ID using Graph API.

Below screenshot is from Graph Explorer (Graph Explorer | Try Microsoft Graph APIs - Microsoft Graph). 

I have formatted the Graph API url and executed from Graph Explorer and below is the output.




Graph API url:

https://graph.microsoft.com/v1.0/sites/<site-id>/lists/<list-name>/Items?expand=fields(select=Id,Column1,Column2,Column3)&filter=fields/ID eq <item-id>

we have to use header key value (highlighted in green arrow on above screenshot) as because filter works only on indexed columns

Header: Prefer 
Value: HonorNonIndexedQueriesWarningMayFailRandomly

(Replace the site-id, list-name, column name, item-id with your actual values.)

On executing above API with actual values, response will be returned with respective list item

However, instead of filter by ID, we can directly access the particular list item by passing ID like below

And this is the Microsoft Recommended Approach in terms of performance


Passing the item ID in-line with the graph API will get the respective SharePoint List Item.
And in this way we do not need to use header and value.

Graph API url:

https://graph.microsoft.com/v1.0/sites/<site-id>/lists/<list-name>/Items/<item-id>?expand=fields(select=Id,Column1,Column2,Column3)


Incase, if you want to execute in C# you can try like below

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

var listItem = await graphClient.Sites[<SiteID>].Lists["<ListName>"].Items["<ItemID>"]
    .Request()
    .GetAsync();

Happy PC (Programming / Configuring)

Comments

Popular posts from this blog

In C# CSOM How to Delete Folders Recursively, Sub-Folders, Files in SharePoint Online Document Library

How Get, Set, Delete Permission on SharePoint Online Site using Graph API

What is SharePoint online default authentication method? And which credential flow it is using to authenticate?