Extensis Logo SUPPORT | FORUMS | KNOWLEDGE BASE

Accessing Thumbnails from NetPublish


#1

Hello -
We are using Soap to allow our Content Providers to browse a NetPublish Site Via WordPress’ Media Library.
Recently the NetPublish Site has had a Site Password set to limit access.

Now the WordPress content providers can no longer preview the thumbnails & import the images via the WP’s Media Library.

Is there away to embed the Netpublish Site Password into our Soup Client ?

Thanks


#2

Hi,

Yes, it is possible for your SOAP client to authenticate and then preview thumbnails and retrieve images.
You’ll need to have your code log in to Portfolio and retrieve a session id. You then pass that session id into other methods.
Take a look at our docs here:
http://doc.extensis.com/api/portfolio/CodeSamples/loginAndLogout.html#java

Please feel free to give us any more info on what client language you’re using, and what API methods you’re consuming, and we point you at relevant example code.

Thanks,
-Loren


#3

Hello Loren –
Wordpress is written in PHP. Our code currently does store the session id on login and use it when calling API methods

If the netpublish site has a ‘site password’ set for control access via the Portfolio interface, then our api client is not able to view/import the images

If the netpublish site does not have a site password, then our api client is able to view/import the images

Below I have included a sample of our code including the functions used to establish a connection to Extensis, prepare query parameters and 2 of queries to the API
Thanks,
Sue

	/**
	 * Return a configured Extensis client
	 *
	 * @return \SoapClient
	 */
	public function get_client() {
		if ( is_null( $this->client ) ) {
			try {
				$client = $this->connect();
			} catch ( \Exception $e ) {
				return new \WP_Error( 'api_connection_failure', $e->getMessage() );
			}
		}

		return $this->client;
	}

    /**
	* Establish an authenticated session with the Extensis API
	*
	* @return  \SoapClient
	*/
	public function connect() {
		if ( is_null( $this->client ) ) {
			$wsdl = 'http://' . $this->settings['host'] . ':' . $this->settings['port'] . '/ws/1.0/AssetService?wsdl';
			$client = new \SoapClient( $wsdl, array( 'connection_timeout' => 10 ) );
			// Fetch public RSA key from Extensis server
			$response = $client->getRSAPublicEncryptionKey();
			$key = $response->return;
			$modulus = new BigInteger( $key->modulusBase16, 16 );
			$exponent = new BigInteger( $key->exponent );
			$rsa = new RSA();
			$publickey = array( 'modulus' => $modulus, 'e' => $exponent );
			$rsa->loadKey( $publickey, RSA::PUBLIC_FORMAT_RAW );
			$rsa->setEncryptionMode( RSA::ENCRYPTION_PKCS1 );
			$encrypted_password = base64_encode( $rsa->encrypt( $this->settings['password'] ) );
			// Login
			$response = $client->login(array(
				'userName'            => $this->settings['user'],
				'encryptedPassword'   => $encrypted_password
			));
			$session_id = $response->return;
			// Store client and session ID
			$this->client = $client;
			$this->session_id = $session_id;
			return $this->client;
		}
	}



/**
	 * Find media assets.
	 *
	 * @param  array  $params    See `Extensis::prepare_params`.
	 * @return array|\WP_Error   A collection of \XXXX\Media\Models\Asset objects, or \WP_Error object on failure.
	 */
	public function find( $params = array() ) {
		$extensis = $this->get_client();
		if ( is_wp_error( $extensis ) ) {
			return $extensis;
		}

		// Prepare query parameters
		list( $query, $result_options ) = $this->prepare_params( $params );

		try {
			$response = $extensis->getAssets( array(
				'sessionId'     => $this->session_id,
				'catalogId'     => $this->settings['catalog_id'],
				'assets'        => $query,
				'resultOptions' => $result_options,
			) );
		} catch ( \Exception $e ) {
			return new \WP_Error( 'api_request_failure', $e->getMessage() );
		}

		$response = $response->return;
		if ( ! isset( $response->assets ) ) {
			$response->assets = array();
		} else if ( is_object( $response->assets ) ) {
			$response->assets = array( $response->assets );
		}

		$assets = array_map( array( $this, 'prepare_asset' ), $response->assets );

		return array( 'assets' => $assets, 'total' => $response->totalNumberOfAssets );
	}

	/**
	 * Retrieve a single asset from the Extensis API
	 *
	 * @param  string $id      Source asset ID
	 * @return array|\WP_Error
	 */
	public function get( $id ) {
		$extensis = $this->get_client();
		if ( is_wp_error( $extensis ) ) {
			return $extensis;
		}

		// Filter Assets by ID
		$id_search = new \stdClass();
		$id_search->operator = 'assetsById';
		$id_search->values = array( (string) $id );

		$query = new \stdClass();
		$query->queryTerm = $id_search;

		$args = array(
			'sessionId'     => $this->session_id,
			'catalogId'     => $this->settings['catalog_id'],
			'assets'        => $query,
		);

		try {
			$response = $extensis->getAssets( $args );
		} catch ( \Exception $e ) {
			return new \WP_Error( 'api_request_failure', $e->getMessage() );
		}

		$asset = null;

		if ( isset( $response->return ) &&
			isset( $response->return->assets ) &&
			is_object( $response->return->assets ) ) {
			$asset = $this->prepare_asset( $response->return->assets );
		}

		return $asset;
	}

	/**
	 * Translate query parameters to Extensis API AssetQuery and ResultOptionsQuery
	 *
	 * @see  http://doc.extensis.com/api/portfolio/assets_assetQuery.html
	 * @see  http://doc.extensis.com/api/portfolio/assets_assetQueryTerm.html
	 * @see  http://doc.extensis.com/api/portfolio/assets_assetQueryResultOptions.html
	 *
	 * @param array $params {
	 *     An array of query parameters for the list media endpoint.
	 *
 	 *     @type string    $search     Search string.
 	 *     @type string    $orderby    Field to order by. One of 'date' or 'name'.
 	 *     @type string    $order      Order direction -- 'asc' or 'desc'.
 	 *     @type int       $per_page   Number of items to return per page.
 	 *     @type int       $page       Current page offset.
 	 * }
	 *
	 * @return array An array with `assets` and `resultOptions` filter objects for a `getAssets` request.
	 */
	public function prepare_params( $params = array() ) {
		// Container for `assets` query
		$query = new \stdClass();

		// Container for query terms. (e.g. search terms).
		$queryTermSubqueries = array();

		// Filter by extension. Only support web-friendly image formats.
		$supported_extensions = apply_filters( 'XXXX_media_extensis_supported_extensions', array( 'jpg', 'png', 'bmp' ) );

		$extensionTerms = new \stdClass();
		$extensionTerms->operator = 'operatorOr';
		$extensionTerms->subqueries = array();

		foreach ( $supported_extensions as $ext ) {
			$extensionTerm = new \stdClass();
			$extensionTerm->fieldName = 'Extension Win';
			$extensionTerm->operator = 'equalValue';
			$extensionTerm->values = $ext;

			$extensionTerms->subqueries[] = $extensionTerm;
		}

		$queryTermSubqueries[] = $extensionTerms;

		// Search
		if ( isset( $params['search'] ) && ! empty( $params['search'] ) ) {
			$searchTerm = new \stdClass();
			$searchTerm->operator = 'matchUnparsedQueryString';
			$searchTerm->values = array( $params['search'] );

			$queryTermSubqueries[] = $searchTerm;
		}

		// Include by ID
		if ( isset( $params['include'] ) ) {
			$assetsByIdTerm = new \stdClass();
			$assetsByIdTerm->operator = 'assetsById';
			$assetsByIdTerm->values = $params['include'];

			$queryTermSubqueries[] = $assetsByIdTerm;
		}

		// Merge query term queries.
		if ( $queryTermSubqueries ) {
			if ( count( $queryTermSubqueries ) > 1 ) {
				$queryTerm = new \stdClass();
				$queryTerm->operator = 'operatorAnd';
				$queryTerm->subqueries = $queryTermSubqueries;
			} else {
				$queryTerm = reset( $queryTermSubqueries );
			}
			$query->queryTerm = $queryTerm;
		}

		// Sort
		$sortOptions = new \stdClass();
		$sortOptions->sortFieldName = 'Created';
		$sortOptions->sortOrderAscending = false;

		if ( isset( $params['orderby'] ) ) {
			if ( 'name' == $params['orderby'] ) {
				$sortOptions->sortFieldName = 'Filename';
			} else if ( 'date' == $params['orderby'] ) {
				$sortOptions->sortFieldName = 'Created';
			}
		}
		if ( isset( $params['order'] ) ) {
			if ( 'asc' == strtolower( $params['order'] ) ) {
				$sortOptions->sortOrderAscending = true;
			} else {
				$sortOptions->sortOrderAscending = false;
			}
		}
		$query->sortOptions = $sortOptions;

		// Container for `resultOptions` query
		$result_options = new \stdClass();

		// Field names to return
		$result_options->fieldNames = array(
			'Filename',
			'File Description',
			'File Size',
			'Thumbnail Size',
			'Width',
			'Height',
			'Created',
			'Last Modified',
			'Updated By',
			'Extension Win',
		);

		// Pagination
		$result_options->pageSize = 10;
		$result_options->startingIndex = 0;

		if ( isset( $params['per_page'] ) ) {
			$result_options->pageSize = (int) $params['per_page'];
		}
		// Calculate starting index by multiplying provided offset times the current page size
		if ( isset( $params['page'] ) ) {
			$result_options->startingIndex = $result_options->pageSize * ( (int) $params['page'] - 1 );
		}

		return array( $query, $result_options );
	}

#4

So if I understand correctly, you have code that currently logs in and stores a session id, and you can retrieve assets. But you also have want Wordpress to retrieve asset thumbnails and originals, and that part is failing after you set a NP site password. Is that correct?

We have simple REST endpoints for retrieving asset thumbnails, originals, and derivatives. Could you have WP use those endpoints? It would be as simple as:

server:8090/api/v1/catalog/90112987-E9D1-A657-52CA-6A015FB0C23F/asset/250135/thumbnail?session=77769A4A-8D95-69A0-76C5-791AF6D2F74A

Note you’ll need the catalog id, the asset id, and the session id.


#5

:nerd: Greetings , Sue !

It sounds like your development team may require more personalized assistance as you transition over to the Portfolio API ( SOAP / REST ).

As Loren mentioned , you may find that the REST API is a better fit for your project and may also want to take advantage of Portfolio’s “token authentication” capabilities.

Portfolio’s REST and SOAP API documentation + examples are listed directly below. Also , I will have a member of the Extensis Sales Team contact you with Integration & Consulting Services pricing.


REST API Documentation

SOAP API Documentation + Examples
http://doc.extensis.com/api/portfolio/index.html

SOAP API – “Perform a search to return a collection of Assets” :
http://doc.extensis.com/api/portfolio/CodeSamples/GetAssets.html#PHP


#6

Thank you! I dig in and give it a try.