I am trying to add some metadata to my file I uploaded into Sharepoint. In Sharepoint I added "columns" for "DocumentType" and "User". But when I run my code to add the values to the file that was uploaded I get an error saying
com.microsoft.graph.http.GraphServiceException: Error code: invalidRequest Error message: Invalid request
or when I was using patch() I get
com.microsoft.graph.http.GraphServiceException: Error code: invalidRequest Error message: Field 'id' is not recognized
I am not ever adding an 'id' field, and I don't see one already in the FieldValueSet.
private addMetadataToFile(PlatformOidcUser platformOidcUser, ListItem file, String itemPath, Map<String, String> metaData) {
FieldValueSet fieldValueSet = file.fields
metaData.each {data -> {
fieldValueSet.additionalDataManager().put(data.key, new JsonPrimitive(data.value))
}}
graphServiceClient.groups(platformOidcUser.defaultGroupId)
.drive()
.root()
.itemWithPath(itemPath)
.listItem()
.fields()
.buildRequest()
.put(fieldValueSet)
}
I've also tried calling patch(fieldValueSet). Also with no values in the map to add, such that the fieldValueSet has all the values the ListItem had when I retrieved it from the Graph API with the following code.
private ListItem retrieveListItemFromFile(PlatformOidcUser platformOidcUser, String itemPath) {
return graphServiceClient.groups(platformOidcUser.defaultGroupId)
.drive()
.root()
.itemWithPath(itemPath).listItem()
.buildRequest().get()
}
I can't figure out what is wrong, why it doesn't work. I have spent over 6 hours on this one thing. And I have lost all my hair now. ;)