The JavaScript client library for the Nuxeo Automation and REST API.
The library can work in a browser (jQuery), or in Node.js, using the same API.
- Get a nuxeo distribution.
- Move sample-1.0-SNAPSHOT.jar into
NUXEO_HOME/nxserver/bundles
folder. - Go to
NUXEO_HOME/bin
folder. - Execute
./nuxeoctl console
. - Navigate with your web browser to
http://localhost:8080/nuxeo/welcome.html
. - Then to the client app:
http://localhost:8080/nuxeo/restapi.html
.
Finally
- Open/Edit
nuxeo/nxserver/nuxeo.war/restapi.js
(ornuxeo\nxserver\nuxeo.war\restapi.js
) - And refresh
http://localhost:8080/nuxeo/restapi.html
after coding.
Warning
If you use the sample 'outside' Nuxeo server, you have to create a cors-config.xml
into NUXEO_HOME/nxserver/config
folder with the following contribution:
<?xml version="1.0"?>
<component name="org.nuxeo.cors">
<extension target="org.nuxeo.ecm.platform.web.common.requestcontroller.service.RequestControllerService" point="corsConfig">
<corsConfig name="foobar" allowOrigin="*" supportedMethods="GET, POST, PUT, DELETE, HEAD, OPTIONS">
<pattern>.*</pattern>
</corsConfig>
</extension>
</component>
in order to resolve CORS issues.
To be able to make API calls on a Nuxeo server, you need to create a Client
object:
var client = new nuxeo.Client({
baseURL: 'http://demo.nuxeo.com/nuxeo',
username: 'Administrator',
password: 'Administrator'
})
client.schema("dublincore");
client.timeout(3000);
return client;
client.timeout(timeout) Sets the common timeout in ms to be used for the requests.
client.header(name, value)
client.headers(headers)
client.repositoryName(repositoryName)
client.schema(schema)
client.schemas(schemas) (X-NXDocumentProperties
header)
Use this.client
to get Client for all examples now.
####Request Object
Fetching vpasquier user: (using user/{userName}
endpoint)
this.client.request('user/vpasquier').get(callback)
Calling endpoint path/
var request = this.client.request('path/');
You can have access to the following methods.
request.path(path)
request.get(options, callback)
request.post(options, callback)
request.put(options, callback)
request.delete(options, callback)
Use GET method and query
endpoint with ?query=SELECT * .....
path parameter.
Fetch the Root document:
this.client.document('/').fetch(callback);
Create a document:
this.client.document('/')
.create({
type: 'Folder',
name: 'My Folder',
properties: {
"dc:title": "My Folder",
"dc:description": "A Simple Folder"
}
You can have access to the following methods.
document.children(callback)
document.fetch(callback)
document.create(doc, callback)
document.update(data, callback)
document.delete(callback)
document.set(properties)
document.save(callback)
document.header(head,value)
document.schemas(schemas)
Use schemas method.
Use content enricher with X-NXContext-Category
header = "acls".
Use document.set(properties) and document.save(callback)
with this.currentDocument
Hint:
properties: {
"dc:title": map["dc:title"],
"dc:description": map["dc:description"],
"dc:nature": map["dc:nature"],
"dc:language": map["dc:language"]
}
Retrieving the Root children document:
client.operation('Document.GetChildren')
.input('doc:/')
.execute(function(error, children) {
if (error) {
// something went wrong
throw error;
}
console.log('Root document has ' + children.entries.length + ' children');
});
You can have access to the following methods.
operation.input(object)
operation.param(name, value)
operation.params(params)
operation.context(context)
operation.execute(callback)
Upload a blob to an existing document. In this example, file
is a File JavaScript object, as filled when using the <input type="file" .../>
HTML object.
// Create the uploader bound to the operation
var uploader = client.operation("Blob.Attach")
.params({ document: existingDocId,
save : true,
xpath: "file:content"
})
.uploader();
// Upload the file
uploader.uploadFile(file, function(fileIndex, file, timeDiff) {
// When done, execute the operation
uploader.execute(function(error, data) {
if (error) {
// something went wrong
throw error;
}
// successfully attached blob
});
}
Use FileManager.Import
operation.
Use Blob.Attach
operation.