microsoftgraph/msgraph-sdk-dotnet-contrib

How do you get List items?

Closed this issue · 7 comments

Could not figure out Simple list Items like

/_api/lists/getbytitle('ECG-Document-Number-Master')/items?$select=Title,Created

Or

/_api/lists/getbytitle('ECG-Document-Number-Master')/items(24)?$select=Title,Created

How do I do it with:

GraphServiceClient spServiceClient

Thanks

List items are available in the Microsoft Graph library, so they are not included in this extension.

https://docs.microsoft.com/en-us/graph/api/listitem-get?view=graph-rest-1.0&tabs=http

That's a shame because with Graph I need to do 3 calls:

  1. Get the {site-id} from the URL
  2. Get the {list-id} from the {site-id} and list name
  3. Get the items with graphClient.Sites["{site-id}"].Lists["{list-id}"].Items

I was hoping for something simpler like PNP/JS but for .NET core

Thanks anyway

That is a valid point. (Mentioning @darrelmiller and @JeremyKelley for visibility.)

I'm open to a ListItem request builder. I just haven't had a need for it. I'm curious how you would know the specific List/Item ids? I would normally expect that those values are stored in response to a user action. So why not just save the graph-provided ids?

Something like I do with HttpClient

await client.GetStringAsync({URL}/_api/lists/getbytitle('ECG-Document-Number-Master')/items?$select=ID,Title,Created" to returen a list (Array) Or if the ID is known, than )/items(ID)?$select=ID,Title,Created" or /items/ID?...

But without all the gagliguk around it (headers tokens ...). Just use the same security.
PNP/JS has a nice implementation of SharePoint's Rest

const w = Web(window.location.origin + "/sites/{site}"); or
const w = Web({full url}); 
const r: [] = await w.lists.getByTitle({List name}).items.select('Title', 'Id', 'ProjectNumber').orderBy('Title').get();

That will save a lot of plumbing code
I for one will be very thankful. 👍

Thank you

How do you know the list title is 'ECG-Document-Number-Master'? Cause however you get that, you could get the IDs. Then it is easy enough to construct the Graph url.

I guess what I'm saying is that the first two calls in your note are only required once. So I wouldn't say that is a blocker to move code to use Graph, IMNSHO...

The SharePoint list title and the URL of the Site, are always known to the application builder.
It may come from another method or be the target of the query. For the list ID (Guid) you need to run something like:

https://graph.microsoft.com/v1.0/sites/{host}:{managedPath}?$select=ID
Then use the ID for Lists
https://graph.microsoft.com/v1.0/sites/{siteID}/lists 
Then find the ID of the list in the results
and only then you can do 
https://graph.microsoft.com/v1.0/sites/{site ID}/lists/{List ID}/Items?expand=fields(select=Title,DocumentName)

Am I wrong? is there an easier way?

You are not wrong. The application builder could easily use Graph Explorer to run the first two requests, then put the values into the application configuration. That is what I would typically do.

That is why this extension does not replicate the Lists functionality. Seems to be more work that it is worth, at least for me.

But, it is GitHub and PRs are a thing. ;)