How do you fetch Microsoft SharePoint Lists from a Site in 6.4.0 version of Graph SDK?

24 views Asked by At

In the Microsoft Graph SDK for Java, there used to be a method

graphClient.sites("YOUR_SITE_ID").lists("YOUR_LIST_ID").items().buildRequest()

You could use it like this:

        GraphServiceClient<Request> graphClient = GraphServiceClient
                .builder()
                .authenticationProvider(authProvider)
                .buildClient();

        // Make a request to get list items
        IListRequest request = graphClient.sites("YOUR_SITE_ID").lists("YOUR_LIST_ID").items().buildRequest();
        
        try {
            ListCollectionPage listPage = request.get();

When I pull in

    <microsoft-graph.version>6.4.0</microsoft-graph.version>

    <dependency>
      <groupId>com.microsoft.graph</groupId>
      <artifactId>microsoft-graph</artifactId>
      <version>${microsoft-graph.version}</version>
    </dependency>

I do not seem to have the the buildRequest method any more.

What is the equivalent in this newer version?

1

There are 1 answers

0
user2250152 On BEST ANSWER

buildRequest doesn't exist any more. The code for SDK v6 to get list items will look like this

ListItemCollectionResponse response = graphClient.sites().bySiteId("{site_id}").lists().byListId("{list_id}").items().get()

To iterate all pages, use PageIterator

List<ListItem> allListItems = new LinkedList<>();

PageIterator<ListItem, ListItemCollectionResponse> pageIterator = new PageIterator.Builder<ListItem, ListItemCollectionResponse>()
    .client(graphClient)
    // The first page of the collection is passed to the collectionPage method
    .collectionPage(response)
    // CollectionPageFactory is called to create a new collection page from the nextLink
    .collectionPageFactory(ListItemCollectionResponse::createFromDiscriminatorValue)
    // ProcessPageItemCallback is called for each item in the collection
    .processPageItemCallback(li -> {
        allListItems.add(li);
        return true;
    }).build();
// Handles the process of iterating through every page and every item         
pageIterator.iterate();

https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#pageiterator