The methode for updating Metadata in SharePoint does not support nested files (unlike Microsoft Graph API)
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.