Creating a new entrey in Vocabulary using automation or REST Api

Hello I get desesperate trying to create a new entry in a Vocabulary using automation (or REST Api). I found the Directory.CreateEntries operations which seems to do exactly what I want.

I prepared a json data file, as described in http://explorer.nuxeo.com/nuxeo/site/distribution/current/viewOperation/Directory.CreateEntries

 {
    "params": {
        "directoryName": "documentationTypes",
        "entries":[{"id":"helptext", "label":"Cool documentation is cool"}]
    },
    "context": {}
 }

And POSTed it to server : http –json POST localhost/nuxeo/site/automation/Directory.CreateEntries < data.json.

But then I get a 500 error message with following log in nuxeo.log

****** chain ******
Name: Directory.CreateEntries
Exception: OperationException
Caught error: No type adapter found for input: class java.util.ArrayList and output class java.lang.String
Caused by: null
****** Hierarchy calls ******
        org.nuxeo.ecm.automation.core.operations.services.directory.CreateDirectoryEntries

        at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:230)
        at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:114)
        at org.nuxeo.ecm.automation.server.jaxrs.OperationResource.execute(OperationResource.java:51)
        at org.nuxeo.ecm.automation.server.jaxrs.ExecutableResource.doPost(ExecutableResource.java:61)
        ... 92 more
Caused by: org.nuxeo.ecm.automation.OperationException: No type adapter found for input: class java.util.ArrayList and output class java.lang.String
        at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.getAdaptedValue(OperationServiceImpl.java:469)
        at org.nuxeo.ecm.automation.core.impl.OperationTypeImpl.inject(OperationTypeImpl.java:261)
        at org.nuxeo.ecm.automation.core.impl.OperationTypeImpl.newInstance(OperationTypeImpl.java:213)
        at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:129)
        at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:145)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:128)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:114)
        at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:206)
        ... 95 more

The server is running latest 7.3 ; I'm pretty sure about about the data.json file since the same file used to read entries works perfect. Note that I'm getting same error for other vocabularies or if I try to delete any entry/entries.

Any hint?? What is this about =

No type adapter found for input: class java.util.ArrayList and output class java.lang.String

Many thanks Lisa

0 votes

1 answers

5690 views

ANSWER



This happens because the entries parameter must be a string which contains a JSON array notation. Try with

"entries":"[{\"id\":\"helptext\", \"label\":\"Cool documentation is cool\"}]"

Also dont forget to set the “Content-Type” header to “application/json+nxrequest; charset=UTF-8”

0 votes