microsoftgraph / msgraph-sdk-java

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

The methode for updating Metadata in SharePoint does not support nested files (unlike Microsoft Graph API) #2031

Closed MalekSmida closed 3 months ago

MalekSmida commented 4 months ago

Issue

The methode for updating Metadata in SharePoint does not support nested files (unlike Microsoft Graph API)

Expected behavior

After uploading a file to SharePoint using this methode

public void uploadFile(String fileName, byte[] fileContent) {
        graphClient
                .sites(sharePointParameters.getSiteId())
                .drives(sharePointParameters.getDriveId())
                .root()
                .itemWithPath(sharePointParameters.getFolderPath() + "/" + fileName)
                .content()
                .buildRequest()
                .put(fileContent);
    }

Being able to update metadata of the uploaded file via this methode

public void updateMetaData(String fileName, String testMetadataId) {
        FieldValueSet fields = new FieldValueSet();
        fields.additionalDataManager().put("testMetadataId",
                new JsonPrimitive(testMetadataId));

        graphClient
                .sites(sharePointParameters.getSiteId())
                .drives(sharePointParameters.getDriveId())
                .root()
                .itemWithPath(sharePointParameters.getFolderPath() + "/" + fileName)
                .listItem()
                .fields()
                .buildRequest()
                .patch(fields);
    }

Actual behavior

While the upload function works well, the update metadata method return 404:Not found

When testing the same API via postman https://graph.microsoft.com/v1.0/sites/{{site-id}}/drives/{{drive-id}}/root:/{{folder-path}}/{{filename}}:/listItem/fields to add metadata, it works fine with the same URL and on the same file.

After investigation, we found that if we upload the file directly into the documents drive, the updating metadata works fine, while in a nested folder with the path sharePointParameters.getFolderPath() + "/" + fileName it does not work

Here is the code that works:

public void uploadFile(String fileName, byte[] fileContent) {
        graphClient
                .sites(sharePointParameters.getSiteId())
                .drives(sharePointParameters.getDriveId())
                .root()
                .itemWithPath(fileName)
                .content()
                .buildRequest()
                .put(fileContent);
    }

public void updateMetaData(String fileName, String testMetadataId) {
        FieldValueSet fields = new FieldValueSet();
        fields.additionalDataManager().put("testMetadataId",
                new JsonPrimitive(testMetadataId));

        graphClient
                .sites(sharePointParameters.getSiteId())
                .drives(sharePointParameters.getDriveId())
                .root()
                .itemWithPath(fileName)
                .listItem()
                .fields()
                .buildRequest()
                .patch(fields);
    }

Steps to reproduce the behavior

Framework Springboot 2.6.7

Used libraries microsoft-graph 5.0.0, azure-identity 1.11.0

Context After authentication via azure-identity, we are using microsoft graph api via Java SDK to upload file to SharePoint then adding metadata to it.

fey101 commented 3 months ago

Thanks for raising this @MalekSmida . Have you tried testing the same on sdk version 6?

microsoft-github-policy-service[bot] commented 3 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.