PHP Automation Client

A PHP automation client is made available on GitHub. You can use it and ask for commit rights on the project if you want to improve it or fix a bug. The project contains the library and some sample use cases.

Queries / Chains

In this examples we are using the PHP automation client to demonstrate how to invoke remote operations. The following example is executing a simple query against a remote server: SELECT * FROM Document. The server will return a JSON document listing all selected documents.


$client = new NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');

$session = $client->getSession('Administrator','Administrator');

$answer = $session->newRequest("Document.Query")->set('params', 'query', "SELECT * FROM Document" )->sendRequest();

$documentsArray = $answer->getDocumentList();
$value = sizeof($documentsArray);
echo '
echo '

<TH>Download as PDF</TH>';
for ($test = 0; $test < $value; $test ++){
    echo '
    echo '
<td> ' . current($documentsArray)->getUid()  . '</td>';
    echo '
<td> ' . current($documentsArray)->getPath()  . '</td>';
    echo '
<td> ' . current($documentsArray)->getType()  . '</td>';
    echo '
<td> ' . current($documentsArray)->getState()  . '</td>';
    echo '
<td> ' . current($documentsArray)->getTitle()  . '</td>';
    echo '
<td><form id="test" action="../tests/B5bis.php" method="post" >';
    echo '<input type="hidden" name="data" value="'.
    current($documentsArray)->getPath(). '"/>';
    echo '<input type="submit" value="download"/>';
    echo '</form></td></tr>';
echo '</table>';

The class NuxeoPhpAutomationClient allows you to open a session with the getSession (return a session instance). Then, from the session, you can create a new request by using the same named function. The set function is used to configure your automation request, giving the chain or operation to call as well as the loading params, context, and input parts. At last, you send the request with the sendRequest function.

You can see here how to use the getters in order to retrieve information from the Document object, built from the request answer.

Using Blobs

Attach Blob

In order to attach a blob, we have to send a Multipart Request to Nuxeo. The first part of the request will contain the body of the request (params, context ...) and the second part will contain the blob (as an input).

$client = new NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');

$session = $client->getSession('Administrator','Administrator');

$answer = $session->newRequest("Blob.Attach")->set('params', 'document', $path)
->loadBlob($blob, $blobtype)

That will attach the blob to an existing file. In order to send a blob, you use the loadBlob() function. If a blob is loaded using this function, the sendRequet() function will automatically create a multipart request. If you load many blobs without noticing a precise localization in params, the blobs will be send as an attachment of the file (not as a content).

Get a Blob

In order to get a blog, you have to read the content of the 'tempfile' after using the appropriate headers.

$client = new NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');

$session = $client->GetSession('Administrator','Administrator');

$answer = $session->NewRequest("Blob.Get")->Set('input', 'doc: ' . $path)->SendRequest();

if (!isset($answer) OR $answer == false)
    echo '$answer is not set';
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.$filename.'.pdf');

This will download the blob placed in file:content of the Nuxeo file designed by $path.

5 months ago GitHub NXDOC-1386: Fix config instruction
4 years ago Solen Guitter 15 | pdate client name (NuxeoPhpAutomationClient
5 years ago Solen Guitter 14
5 years ago Solen Guitter 13 | Added TOC and excerpt
6 years ago Solen Guitter 11 | Fixed file:content interpreted as a link
6 years ago Solen Guitter 12 | Migrated to Confluence 4.0
8 years ago Arthur Gallouin 10
8 years ago Arthur Gallouin 9
8 years ago Arthur Gallouin 8
8 years ago Alain Escaffre 7
8 years ago Arthur Gallouin 6
8 years ago Arthur Gallouin 5
8 years ago Arthur Gallouin 4
8 years ago Arthur Gallouin 3
8 years ago Arthur Gallouin 2
8 years ago Arthur Gallouin 1
History: Created by Arthur Gallouin

We'd love to hear your thoughts!

All fields required