microsoftgraph / msgraph-sdk-java

Microsoft Graph SDK for Java
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
403 stars 134 forks source link

Workbooks: Update range of a worksheet not implemented in sdk #2202

Open lombold opened 1 month ago

lombold commented 1 month ago

Is your feature request related to a problem? Please describe the problem.

I want to update a range within a worksheet and noticed that the update range endoint (PATCH /drive/items/{id}/workbook/worksheets/{sheet-id}/range(address='A1:B2')) cannot be called via the msgraph-sdk for java.

API Docs: https://learn.microsoft.com/en-us/graph/api/range-update?view=graph-rest-1.0&tabs=http

SDK-Version: 6.18.0

Describe the solution you'd like.

I would be glad if you could extend the sdk to support this functionality.

E.g. something like this:

myGraphServiceClient
          .drives()
          .byDriveId(driveId)
          .items()
          .byDriveItemId(documentId)
          .workbook()
          .worksheets()
          .byWorkbookWorksheetId(worksheet)
          .rangeWithAddress(address)
          .patch(patchRequest);

Additional context?

My current workaround is

final var updateRangeRequest = new UntypedObject(Map.of(
    "values", new UntypedArray(Arrays.asList(
      new UntypedArray(Arrays.asList(
        new UntypedString(value)
      ))
    ))
  ));

  final var requestInfo = graphServiceClient
    .drives()
    .byDriveId(this.driveId)
    .items()
    .byDriveItemId(documentId)
    .workbook()
    .worksheets()
    .byWorkbookWorksheetId(worksheet)
    .rangeWithAddress(address)
    .toGetRequestInformation();

// Convert the get-request to the desired patch
  requestInfo.headers.tryAdd("workbook-session-id", sessionId);
  requestInfo.httpMethod = HttpMethod.PATCH;
  requestInfo.setContentFromParsable(graphServiceClient.getRequestAdapter(), "application/json", updateRangeRequest);

// Copied from sdk
  HashMap<String, ParsableFactory<? extends Parsable>> errorMapping = new HashMap();
  errorMapping.put("XXX", ODataError::createFromDiscriminatorValue);

  final var updatedRange = (WorkbookRange) graphServiceClient.getRequestAdapter()
    .send(requestInfo, errorMapping, WorkbookRange::createFromDiscriminatorValue);