Issue
I would like to add metadata to a SharePoint file. When i search the internet I find solutions like
graphClient.sites("{id}").drives("{id}").items("{id}").buildRequest().fields().patch(driveItem);
But I get the following message
Cannot resolve method 'fields' in 'DriveItemRequest'
When looking in the java doc, this method does not exitst.
An other solution is:
var fieldValueSet = new FieldValueSet();
fieldValueSet.additionalDataManager().put("Soort", new JsonPrimitive("Invoice"));
graphClient.sites("{id}").drives("{id}").items("{id}").buildRequest().patch(fieldValueSet );
But now I got the following message
Required type: DriveItem, Provided: FieldValueSet
Sommething else i tried:
FieldValueSet fieldValueSet = new FieldValueSet();
FieldValueSetRequest fieldValueSetRequest = graphClient.sites("{id}").lists("{id}").items({id}).fields().buildRequest();
fieldValueSet.additionalDataManager().put("Soort", new JsonPrimitive("new soort"));
return fieldValueSetRequest.patch(fieldValueSet);
Now I get a 400 back invalidRequest Error message: Invalid request PATCH
I also tried to extend DriveItem
with my own property
CustomDriveItem customDriveItem = new CustomDriveItem();
customDriveItem.soort = "new soort";
return graphClient.sites({id}).drives({id}).items({id}).buildRequest().patch(customDriveItem);
The extended class:
public class CustomDriveItem extends DriveItem {
@SerializedName(value="soort")
@Expose
public String soort;
public CustomDriveItem() {
super();
}
}
This also gives me a 400 back invalidRequest Error message: Invalid request PATCH
Solution
The driveItem
object does not have fields
- you'll need to transition to a listItem
to access it. You could try:
var fieldValueSet = new FieldValueSet();
fieldValueSet.additionalDataManager().put("Soort", new JsonPrimitive("Invoice"));
graphClient.sites("{id}").drives("{id}").items("{id}").listItem().fields().buildRequest().patch(fieldValueSet );
Answered By - Brad
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)