Java SDK Update metadata attribute on a file

SOLVED
Go to solution
Highlighted
Occasional Contributor

Java SDK Update metadata attribute on a file

Hi,

 

I've troubles updating a metadata attribute on a file.

 

I followed the instructions on the github site and on the documentation site.

BoxFile file = new BoxFile(api, "id");

file.updateMetadata(new Metadata().add("/foo", "bar"));

 

In my case:

 

BoxFile boxBestand = new BoxFile(api, bestandsId);

boxBestand.updateMetadata(new Metadata().add("/"+veld, waarde));

 

Tried:

 

BoxFile boxBestand = new BoxFile(api, bestandsId);

boxBestand.updateMetadata(boxBestand.createMetadata(template, "enterprise",  new Metadata().add("/"+veld, waarde));

 

And tried this method:

 

BoxFile boxBestand = new BoxFile(api, bestandsId);

Metadata metadata = new Metadata();
metadata = boxBestand.getMetadata(template, "enterprise");
metadata = metadata.replace("/"+veld, waarde);
boxBestand.updateMetadata(boxBestand.createMetadata(template, "enterprise", metadata));

 

All I get is 400 errors.

The API returned an error code [400 | bu1qqzggyxcgu1z4.034474d9889552d8bf4cf8604601c282d] schema_validation_failed - object instance has properties which are not allowed by the schema: ["retentiebeleid"]

 

Regards,

 

Marcel

 

 

2 REPLIES 2
Highlighted
Box Employee

Re: Java SDK Update metadata attribute on a file

Is "foo" already a metadata attribute on the file or is something you are adding. If you are adding it, the Github code should work. If you are updating the attribute, then you have to do file.updateMetadata(file.getMetadata().replace("/foo", "bar")) as shown here.

Highlighted
Occasional Contributor

Re: Java SDK Update metadata attribute on a file

Thanks for your feedback.


The problem was that I used the displayed name as path.

If i log in, in the Box web app I see 'retentie' diplayed as metadata attribute.
The attribute has another name as id 'retentieConversion'.

 

Problem solved!