Getting error in updating the Graph API version for creating worksheet

Ashish Kumar 5 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 and Office Development Other
Microsoft 365 and Office Install, redeem, activate For business Windows
Microsoft Security Microsoft Graph
0 comments No comments
{count} vote

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.