Skip to content

Latest commit

 

History

History
236 lines (196 loc) · 6.52 KB

php-automation-client.md

File metadata and controls

236 lines (196 loc) · 6.52 KB
title review labels toc confluence tree_item_index history
PHP Automation Client
comment date status
2016-12-06
ok
lts2016-ok
php
pgmillon
client
php-client-component
content-review-lts2017
true
ajs-parent-page-id ajs-parent-page-title ajs-space-key ajs-space-name canonical canonical_source page_id shortlink shortlink_source source_link
16091040
Client SDKs
NXDOC
Nuxeo Platform Developer Documentation
PHP+Automation+Client
7209503
HwJu
/display/NXDOC/PHP+Automation+Client
600
author date message version
Vincent Dutat
2015-03-25 17:15
17
author date message version
Manon Lumeau
2015-03-18 09:09
16
author date message version
Frédéric Vadon
2015-02-19 04:04
15
author date message version
Solen Guitter
2013-10-17 11:15
14
author date message version
Solen Guitter
2013-08-30 15:05
Added TOC and excerpt
13
author date message version
Solen Guitter
2012-09-14 11:12
Migrated to Confluence 4.0
12
author date message version
Solen Guitter
2012-09-14 11:12
Fixed file:content interpreted as a link
11
author date message version
Arthur Gallouin
2011-05-20 16:40
10
author date message version
Arthur Gallouin
2011-05-20 15:42
9
author date message version
Arthur Gallouin
2011-05-20 15:19
8
author date message version
Alain Escaffre
2011-05-19 20:29
7
author date message version
Arthur Gallouin
2011-05-16 17:41
6
author date message version
Arthur Gallouin
2011-05-16 17:40
5
author date message version
Arthur Gallouin
2011-05-16 17:37
4
author date message version
Arthur Gallouin
2011-05-16 17:28
3
author date message version
Arthur Gallouin
2011-05-10 09:48
2
author date message version
Arthur Gallouin
2011-05-09 16:56
1

The Nuxeo Automation PHP Client is a PHP client library for Nuxeo Automation API.

It is compatible with Nuxeo Platform LTS 2015, LTS 2016 and latest Fast Tracks.

Path to the PHP Client (v1.5)

Version 1.5.0 introduces a new fluent API. The old API is still available. Thus you can upgrade the library to the 1.5 version and access the new API and features without breaking your application.

{{#> panel type='code' heading='version < 1.5.0'}}

$client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');
$session = $client->getSession('Administrator', 'Administrator');
$answer = $session->newRequest("Document.Query")->set('params', 'query', "SELECT * FROM Document)->setSchema($propertiesSchema)->sendRequest();
$documentsArray = $answer->getDocumentList();

{{/panel}}

{{#> panel type='code' heading='version >= 1.5.0'}}

$client = new \Nuxeo\Client\Api\NuxeoClient('http://localhost:8080/nuxeo', 'Administrator', 'Administrator');
$documents = $client->schemas("*")->automation('Document.Query')->param('query', 'SELECT * FROM Document')->execute(Documents::className);

{{/panel}}

Getting Started

Library import

Download the latest stable release Nuxeo Automation PHP Client 1.5.0.

Composer:

  "require": {
    "nuxeo/nuxeo-automation-php-client": "~1.5.0"
  }

Usage

Creating a Client

The following documentation and samples applies for the 1.5 and newer versions. Calls to the Automation API for previous versions of the client will require adjustments.

For a given url:

$url = 'http://localhost:8080/nuxeo';

And given credentials:

use Nuxeo\Client\Api\NuxeoClient;

$client = new NuxeoClient($url, 'Administrator', 'Administrator');

Options:

// For defining all schemas
$client = $client->schemas("*");
// For changing authentication method

use Nuxeo\Client\Api\Auth\PortalSSOAuthentication;
use Nuxeo\Client\Api\Auth\TokenAuthentication;

// PortalSSOAuthentication with nuxeo-platform-login-portal-sso
$client = $client->setAuthenticationMethod(new PortalSSOAuthentication($secret, $username));

// TokenAuthentication
$client = $client->setAuthenticationMethod(new TokenAuthentication($token));

APIs

Automation API

To use the Automation API, Nuxeo\Client\Api\NuxeoClient#automation() is the entry point for all calls:

use Nuxeo\Client\Api\Objects\Document;

// Fetch the root document
$result = $client->automation('Repository.GetDocument')->param("value", "/")->execute(Document::className);
use Nuxeo\Client\Api\Objects\Documents;

// Execute query
$operation = $client->automation('Repository.Query')->param('query', 'SELECT * FROM Document');
$result = $operation->execute(Documents::className);
use Nuxeo\Client\Api\Objects\Blob\Blob;
use Nuxeo\Client\Api\Objects\Blob\Blobs;

// To upload|download blob(s)

$fileBlob = Blob::fromFile('/local/file.txt', 'text/plain');
$blob = $client->automation('Blob.AttachOnDocument')->param('document', '/folder/file')->input($fileBlob)->execute(Blob::className);

$inputBlobs = new Blobs();
$inputBlobs->add('/local/file1.txt', 'text/plain');
$inputBlobs->add('/local/file2.txt', 'text/plain');
$blobs = $client->automation('Blob.AttachOnDocument')->param('xpath', 'files:files')->param('document', '/folder/file')->input($inputBlobs)->execute(Blobs::className);

$resultBlob = $client->automation('Document.GetBlob')->input('folder/file')->execute(Blob::className);

Errors/Exceptions

The main exception type is Nuxeo\Client\Internals\Spi\NuxeoClientException and contains:

  • The HTTP error status code (666 for internal errors)
  • An info message