Adding customize metadata with rest api

I am new to nuxeo and I would like to add customize metadata to the document, in my case it's transaction ID. For example I have created document from the file with rest api:

POST http://nuxeo/nuxeo/api/v1/id/de72f8e6-348e-477b-8824-9b1c157b4f7d

    {
        "entity-type": "document", 
        "name":"HelloWorld.doc", 
        "type": "File",
        "properties": { 
            "dc:title": "HelloWorld.doc", 
            "dc:description": "Created via a so cool and simple REST API", 
            "transaction:ID": "8D9AC546-917B-4FC0-B378-000D4E968601",
            "file:content": {
                "upload-batch":"batchId-2c15a871-0f02-4889-b976-1531e52fcb0d",
                "upload-fileId":"0"
            }
        }
    }

Than I run GET request and got the following response: {

"entity-type": "document",
"repository": "default",
"uid": "3fb01c07-e0cf-4167-ad91-0fa7304a2442",
"path": "/default-domain/workspaces/Sample Content/PDF and Office Documents/HelloWorld.doc",
"type": "File",
"state": "project",
"parentRef": "de72f8e6-348e-477b-8824-9b1c157b4f7d",
"isCheckedOut": true,
"isVersion": false,
"isProxy": false,
"changeToken": "5-0",
"title": "HelloWorld.doc",
"lastModified": "2018-04-27T15:07:47.420Z",
"properties": {
    "uid:uid": null,
    "uid:major_version": 0,
    "uid:minor_version": 0,
    "thumb:thumbnail": {
        "name": "HelloWorld.png",
        "mime-type": "image/png",
        "encoding": null,
        "digestAlgorithm": "MD5",
        "digest": "fc05bb5bc325e52720d11f084d2aa919",
        "length": "756",
        "data": "http://10.204.20.153/nuxeo/nxfile/default/3fb01c07-e0cf-4167-ad91-0fa7304a2442/thumb:thumbnail/HelloWorld.png"
    },
    "file:content": {
        "name": "HelloWorld.doc",
        "mime-type": "application/msword",
        "encoding": null,
        "digestAlgorithm": "MD5",
        "digest": "b275cf878138a65f4aed3324c3f20b78",
        "length": "23040",
        "data": "http://10.204.20.153/nuxeo/nxfile/default/3fb01c07-e0cf-4167-ad91-0fa7304a2442/file:content/HelloWorld.doc"
    },
    "common:icon-expanded": null,
    "common:icon": "/icons/word.png",
    "files:files": [],
    "dc:description": "Created via a so cool and simple REST API",
    "dc:language": null,
    "dc:coverage": null,
    "dc:valid": null,
    "dc:creator": "Administrator",
    "dc:modified": "2018-04-27T15:07:47.420Z",
    "dc:lastContributor": "Administrator",
    "dc:rights": null,
    "dc:expired": null,
    "dc:format": null,
    "dc:created": "2018-04-27T15:07:47.420Z",
    "dc:title": "HelloWorld.doc",
    "dc:issued": null,
    "dc:nature": null,
    "dc:subjects": [],
    "dc:contributors": [
        "Administrator"
    ],
    "dc:source": null,
    "dc:publisher": null,
    "relatedtext:relatedtextresources": [],
    "nxtag:tags": []
},
"facets": [
    "Versionable",
    "NXTag",
    "Publishable",
    "Commentable",
    "HasRelatedText",
    "Thumbnail",
    "Downloadable"
]

}

But I don't see transaction metadata, for example transaction:ID. that I added . Could you please tell me what I am doing wrong.

0 votes

3 answers

97 views

ANSWER



In order to add dynamic custom metadata, you must define a facet that holds a schema defining your custom metadata.

Before adding the metadata, you have to add the facet to the document (automation operation).

Now, it might be easier to create a custom doctype (that inherits File for instance) associated with the same schema

0 votes



I was also searching for the same, but didn't find any clue if we can add custom metadata dynamically in nuxeo. For adding metadata you have to add through nuxeo studio only.

0 votes



Check out Special HTTP Headers: header X-NXDocumentProperties=* https://doc.nuxeo.com/nxdoc/special-http-headers/

0 votes



I am using Postman for the client and in the Headers tab I put the following data: key - X-NXDocumentProperties value - * May be I am doing something wrong. For example I would like to attach to my document(In my case is “HelloWorld.doc”) transaction ID(in my case is “8D9AC546-917B-4FC0-B378-000D4E968601”). Could you please give me an example for POST or PUT request how to do this? Thank you.
04/27/2018

I created new POST request taking from the nuxeo documentation https://doc.nuxeo.com/nxdoc/rest-api-entity-types/#document:

{ "entity-type": "document", "type": "File", "name": "myDocumentName", "properties": {

"dc:title": "My Document Title",
/* Timezone is not needed for dates, but you can add it if you want to */
"myschemaprefix:aDateProperty": "2050-12-25",
/* Multivalued properties have to be sent as javascript arrays... */
"myschemaprefix:aStringMultivaluedProperty": ["some", "text", "here"],
/* Complex properties have to be sent as javascript objects... */
"myschemaprefix:aComplexProperty": {"firstName": "Chuck", "lastName": "Norris", "birthDate": "1968-12-25"}
/* ...So complex multivalued properties are sent as? Object arrays of course! */
"myschemaprefix:aMultivaluedComplexProperty": [
  {"firstName": "Chuck", "lastName": "Norris", "birthDate": "1968-12-25"},
  {"firstName": "Bruce", "lastName": "Lee", "birthDate": "1965-10-21"}
]

} }

But when I run GET request, I am not getting myschemaprefix metadata information. Below is my GET response:

{

"entity-type": "document",
"repository": "default",
"uid": "f04bc6c5-db16-4e99-b526-6f910c5f1b4c",
"path": "/default-domain/workspaces/Sample Content/PDF and Office Documents/Test.doc",
"type": "File",
"state": "project",
"parentRef": "de72f8e6-348e-477b-8824-9b1c157b4f7d",
"isCheckedOut": true,
"isVersion": false,
"isProxy": false,
"changeToken": "1-0",
"title": "Test.doc",
"lastModified": "2018-04-27T21:12:53.620Z",
"properties": {
    "uid:uid": null,
    "uid:major_version": 0,
    "uid:minor_version": 0,
    "file:content": null,
    "common:icon-expanded": null,
    "common:icon": "/icons/file.gif",
    "files:files": [],
    "dc:description": "Test",
    "dc:language": null,
    "dc:coverage": null,
    "dc:valid": null,
    "dc:creator": "Administrator",
    "dc:modified": "2018-04-27T21:12:53.620Z",
    "dc:lastContributor": "Administrator",
    "dc:rights": null,
    "dc:expired": null,
    "dc:format": null,
    "dc:created": "2018-04-27T21:12:53.620Z",
    "dc:title": "Test.doc",
    "dc:issued": null,
    "dc:nature": null,
    "dc:subjects": [],
    "dc:contributors": [
        "Administrator"
    ],
    "dc:source": null,
    "dc:publisher": null,
    "relatedtext:relatedtextresources": [],
    "nxtag:tags": []
},
"facets": [
    "Versionable",
    "NXTag",
    "Publishable",
    "Commentable",
    "HasRelatedText",
    "Downloadable"
]

}

Any help will be appreciated.

04/27/2018