Tim's Weblog
Tim Strehle’s links and thoughts on Web apps, software development and Digital Asset Management, since 2002.
2020-05-20

Open source PHP client for the WoodWing Assets (Elvis) REST API

In my role as “Project Manager for DAM systems” at the SPIEGEL-Verlag, I spent the last year helping to roll out the WoodWing Assets (formerly known as “Elvis”) DAM software. It’s not used for the print publication yet (as this premature press release suggests), but it powers most of the photos published on spiegel.de since the January relaunch.

We decided to open-source the Assets plugins and integrations we and our development partners built during this project – where it makes sense, and as our time permits.

The first open source code we’re publishing is this PHP client library for the Assets REST API:

DerSpiegel / ww_elvis_php_client on Github

Documentation and tests are still missing, but the library is stable (we’re using this code in production). It is pretty lightweight and can be used for one-off batch scripts.

If you have Docker Desktop installed, it’s easy to get started – you don’t need a server, virtual machine, or PHP runtime. This Docker / Composer command fetches the library and all its dependencies:

$ docker run --rm --interactive --tty \
  --volume $PWD:/app \
  --volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp \
  composer require der-spiegel/ww-elvis-client monolog/monolog

Create your first script by copying the provided example:

$ cp vendor/der-spiegel/ww-elvis-client/UsageExample.php MyExample.php

Edit your copy, setting the correct Assets URL, username (API user preferred) and password in this section:

$elvisConfig = new ElvisConfig(
    'https://assets.example.com/', // Assets URL (without app/ postfix)
    'username',                   // Assets user name (API user preferred)
    'password'                    // That user's password
);

The example script performs a simple search across all Elvis assets (visible for that user) and returns the first 50 asset IDs – you can leave it as is for a first test:

$elvisClient = new ElvisClient($elvisConfig, $logger); // Create client

$request = (new SearchRequest($elvisConfig))           // Create search request
    ->setQ('')                                         // Assets query
    ->setMetadataToReturn(['']);                       // Metadata fields to return
    
$response = $elvisClient->search($request);            // Perform search

foreach ($response->getHits() as $assetResponse) {     // Loop through results
    echo $assetResponse->getId() . "\n";               // Access asset metadata
}

Finally, run your script via Docker:

$ docker run -it --rm --name ww-elvis-client-example \
  --volume "$PWD":/usr/src/myapp --workdir /usr/src/myapp \
  php:7.4-cli php MyExample.php

It should display a list of the first 50 asset IDs.

I hope this library is useful to other WoodWing customers. Let me know if you have questions or need help using it!