Extensis Logo SUPPORT | FORUMS | KNOWLEDGE BASE

Extensis Portfolio API - FAQ : [ SOAP ]


#1

:nerd: Yes !

:exclamation: Arrays : Much of your time as a Portfolio API developer will be working with various array structures. Ensure that your code includes logic to test for either no results ( ==0 ), a single result ( ==1 ), or multiple results ( >1 ). Note that the array structure for a single result will be slightly different that the array structure for multiple results :

[code]//—START-GET-CATALOG-ID-----------------------------------------

$response = $client->getCatalogs(array(
‘sessionId’ => $sessionId
));

$catalogs = $response->return;

if (count($catalogs) == 0 ) {

echo "<br><br>" . "ERROR accessing Catalog(s)!!!" . "<br><br>". "Please ensure that [ ". USERNAME ." ] has [ READER ] access to at least 1(one) Portfolio Catalog !" . "<br>";

}

elseif (count($catalogs) == 1 ) {
if($catalogs->name == TARGET_CATALOG)
{
$catalogId = $catalogs->catalogId;
echo “Catalog Name: $catalogs->name”."
";
echo “Catalog ID: $catalogs->catalogId”."
";

}

} else {

foreach ($catalogs as $catalog) {
if($catalog->name == TARGET_CATALOG)
{
$catalogId = $catalog->catalogId;
echo “Catalog Name: $catalog->name”."
";
echo “Catalog ID: $catalog->catalogId”."
";

		}

}

}

//—END-GET-CATALOG-ID----------------------------------------- [/code]

:exclamation: Attributes : When displaying multiple field values ( Filename, Keywords, etc. ) for an item, note that the returned order is random. You will likely need to apply an array sort to ensure that the fields are in an expected order. Notice that in addition to the sort ( in this case, asort or arsort ) we are also testing for zero results, a single result, or multiple results :

[code]//—START-GET-FIELD-INFORMATION----------------------------------------------------------

if ($AssetsResults->totalNumberOfAssets == 0) {

} elseif ($AssetsResults->totalNumberOfAssets == 1) {

$asset = $AssetsResults->assets;

echo '<tr><td>';

echo $asset->assetId;

echo '</td>';

$attributes = $asset->attributes;

// SORT = “Item ID” , “Filename” , FIELD

if (strcasecmp(“Filename”,FIELD) < 0) {
asort($attributes);
} else {
arsort($attributes);
}

	foreach ($attributes as $attribute) {

		if ($attribute->name == "Filename") {
		echo '<td>';
		echo $attribute->values; 
		echo '</td>';
			}

		if ($attribute->name == FIELD) {
		echo '<td>';
		echo date("l, F jS Y",strtotime($attribute->values));  
		echo '</td></tr>';
			}

	}

} else {

$asset = $AssetsResults->assets;

foreach ($asset as $item) {

echo '<tr><td>';

echo $item->assetId;
echo '</td>';

$attributes = $item->attributes;

// SORT = “Item ID” , “Filename” , FIELD

if (strcasecmp(“Filename”,FIELD) < 0) {
asort($attributes);
} else {
arsort($attributes);
}

	foreach ($attributes as $attribute) {

		if ($attribute->name == "Filename") {
		echo '<td>';
		echo $attribute->values; 
		echo '</td>';
			}

		if ($attribute->name == FIELD) {
		echo '<td>';
		echo date("l, F jS Y",strtotime($attribute->values)); 
		echo '</td></tr>';
			}

	}

}

}

//—END-GET-FIELD-INFORMATION----------------------------------------------------------[/code]

:exclamation: Date/Time : When performing search queries against Date/Time field types, note that Portfolio stores Date/Time in UTC. Search results that appear to be off by one day is an indicator that the timezone within your code has not been properly set to UTC :

[code]//—START-SET-TIMEZONE----------

date_default_timezone_set(‘UTC’);

//—END-SET-TIMEZONE------------[/code]