Hi at all, I'm trying to assign to a file in my Box account an existing Metadata Template that I have created with admin console. Throught API get Metadata Template call, I've saved the JSON response with all information in the schema ( such as templateKey, scope, displayName, fields[] etc...).
I've created a MetadataTemplate object with the JSON and try to create a Metadata on a file based to MetadataTemplate, but box sdk return me error code 400.
This is my example code, I don't know where I make mistake =( :
// read the json file
FileReader reader = new FileReader("path/to/file.json");
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
// create template based on JSON stringified
MetadataTemplate imgTemplate = new MetadataTemplate(jsonObject.toJSONString());
// create custom metadata values to add on template
Metadata assignMeta = new Metadata();
assignMeta.add( imgTemplate.getFields().get(0).getKey(),"test");
assignMeta.add( imgTemplate.getFields().get(1).getKey(),"10");
assignMeta.add( imgTemplate.getFields().get(2).getKey(),"png");
// assign template to this file with custom metadata
file.createMetadata(imgTemplate.getTemplateKey(), imgTemplate.getScope(), assignMeta);
Someone can help me please???? I've just tried all in my head...