Getting error in updating the Graph API version for creating worksheet

Ashish Kumar 0 Reputation points
2024-04-16T04:13:27.9466667+00:00

Hello there,

I have written some code for my project, where I'm creating the worksheet using the Graph API version 5.42 in Java.

Now I'm updating the version to the latest one, and it is not showing the below error for the respective code.

Error showing in the below code:

Cannot resolve method 'me()'

Cannot resolve symbol 'WorkbookWorksheetAddParameterSet'

Cannot resolve symbol 'GraphServiceException'

Code:

import com.microsoft.graph.http.GraphServiceException;
import com.microsoft.graph.models.*;
import com.microsoft.graph.options.HeaderOption;
import com.microsoft.graph.requests.GraphServiceClient;
import com.microsoft.graph.requests.WorkbookWorksheetRangeRequest;
private GraphServiceClient client;
public boolean createWorksheet(String worksheetName) {
        try {
            // API call to create new worksheet
            client.me()
                    .drive()
                    .root()
                    .itemWithPath(workbookPath)
                    .workbook()
                    .worksheets()
                    .add(
                            WorkbookWorksheetAddParameterSet.newBuilder()
                              .withName(Utils.encodeString(worksheetName))
                                    .build())
                    .buildRequest(workbookSessionIdHeader)
                    .post();
            setActiveSheetName(worksheetName);
            return true;
        } catch (GraphServiceException exception) {
            System.err.println("Graph service encountered an error: " + exception.getMessage());
        }
    }

This code worked perfectly fine with the older API version, but it's breaking with the newer API version.

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,817 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,624 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,501 questions
0 comments No comments
{count} votes