cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with document creation REST API: document JSON properties in a collection are ignored

russtrotter_
Confirmed Champ
Confirmed Champ

Here's my setup:

  • schema "myschema" defined as single field named "list" of type Complex that is multi-valued
  • the complex sub-schema has 2 string fields "foo" and "bar", neither are multi-valued
  • document type "mydoc" that references this schema
  • modify creation/edit layouts for the document type to use a list widget on the "myschema" schema
  • in Nuxeo DM, create a "mydoc" document titled "mydocinstance" (for testing, i hit the "Add" trigger on the UI and plug in the values "test1" and "test2" for the foo/bar fields respectively)

With that setup I do a GET /nuxeo/api/v1/path/default-domain/workspaces/ws/mydocinstance and get the following JSON:

{
...
  "myschema:list":[
     {
     "foo":"test1",
     "bar":"test2"
     }
  ]
...
}

Now POST to the same API to create a new document: POST /nuxeo/api/v1/path/default-domain/workspaces/ws/mynewinstance

{
...
   "myschema:list":[
         {
         "foo":"testA",
         "bar":"testB"
         }
      ]
    ...
    }

Up to this point, everything looks good, but the problem appears when I GET that new document, e.g. GET /nuxeo/api/v1/path/default-domain/workspaces/ws/mynewinstance and I get:

{
    ...
       "myschema:list":[]
     ...
}

Why do the myschema:foo and myschema:bar sub-properties get ignored in JSON POSTed?

5 REPLIES 5

russtrotter_
Confirmed Champ
Confirmed Champ

Fun, answering my own questions! k, this one took some time, but thanks to Nuxeo DM source being freely available and a debugger, I can now do what i was trying to do!

First off, the TL;DR solution: All fields in the JSON nxentity "properties" map MUST be strings, thus if you are trying to set a complex property, the JSON structure of that complex property MUST be escaped.

For example, in my examples above, I need to escape the JSON subtree of the "myschema:list" property so what gets PUT to the REST API should be:

{
    "properties": {
        "myschema:list": "[{\"foo\":\"myfoo\",\"bar\":\"mybar\"}]"
    }
}

UPDATE: I'm editing my original answer since the Nuxeo folks have fixed this behavior with hotfix release nuxeo-5.8.0-HF01-1.0.0. This update should not require the treatment of the complex fields as strings.

That's not supposed to be the case. You should get proper and readable JSON. I'll raise the issue internally.

This behavior seems to only be the case when sending the JSON nxentity via PUT or POST. On a GET request, the JSON that is returned is "sane" and doesn't require this kind of escaping.

Ok but you should be able to send normal JSON as well. That's the goal of these new APIs.

I've created a ticket here