Extensis Logo SUPPORT | FORUMS | KNOWLEDGE BASE

Edit custom fields using the API


#1

Hello,

I’m trying to edit a custom field using the API. How would that work? We use a lot of custom fields when adding assets to our catalog and I’m not entirely sure how to edit/view custom data.

Best,

Trevor


#2

[quote=“trevors”]Hello,

I’m trying to edit a custom field using the API. How would that work? We use a lot of custom fields when adding assets to our catalog and I’m not entirely sure how to edit/view custom data.
[/quote]

Hi Trevor,

The answer to this question will depend on what you mean by "edit a custom field using the API."
If you are referring to making changes to the structure of a custom field, such as changing the name or the amount of characters allowed by the custom field, then you are out of luck. The Portfolio API does not handle administrative changes to the catalogs, and adding, deleting, and modifying custom fields falls under this category.

However, if you want want to make changes the content of a custom field, such as changing the value ,that is a different story. For example, if you have a custom field called ‘Photographer’ and you want assign the value “Bill the Camera” to that field, then you would use the UpdateAssetFieldValues method.

You can find a code sample demonstrating the use of the this method here: http://doc.extensis.com/api/portfolio-server/UpdateAssetFieldValues.html

If you have any questions, please let me know.

Matt


#3

Hi Matt,

That’s very useful, thank you. I had one more question if you have a minute. I’m trying to create a placeholder script in PHP, and I’m attempting to use addAssetsByPath to add an image then update the files using UpdateAssetFieldValue. The one problem is that I can’t figure out how to designate a local file (say, in img/placeholder.jpg) as the image. Am I going about this the wrong way? Do I need to add the asset, then update the image?

Thanks for any advice you can give.

Best,

Trevor


#4

[quote=“trevors”]I’m trying to create a placeholder script in PHP, and I’m attempting to use addAssetsByPath to add an image then update the files using UpdateAssetFieldValue. The one problem is that I can’t figure out how to designate a local file (say, in img/placeholder.jpg) as the image. Am I going about this the wrong way? Do I need to add the asset, then update the image?
[/quote]

Hi Trevor,

The thing you need to remember when using addAssetsByPath, is that the files need to be directly accessible by the server. What this means is that you cannot use that command for local files. If you want to deal with local files, you will need to upload them to the server using the File Transfer Servlet. You can find a code sample of how to use it here: http://doc.extensis.com/api/portfolio-server/HTTPuploadFile.html#PHP

There is another resource that you can refer to as well. A couple of months ago I wrote a forum post on this topic. It included a sample JAVA program illustrating ways to upload a placeholder. It is not PHP, but it may help you in creating your script. You can find the forum post here: Placeholder objects and the API

If you have any questions or need any help, please let me know.

Matt


#5

Hey Matt,

Thanks for the info, I’m working my way through this. I did have (hopefully) one last question. I took your advice an started using File Transfer Servlet with mostly code from the linked example, but I’m a bit stuck now. I keep getting a internal 500 server error, and I can’t figure out why exactly. I’ve added the code below, anything obvious that jumps out?

[code]UPLOADFOLDER = "::SERVER:C:Images:";
$item = “phthumb.jpg”;
$pFilename = “Placeholder-text”;
$directory = “C:/Images”;
//directory = "::SERVER:C:Images:";
$resourceType = “Photography”;

// Create Boundary
$boundary = uniqid();
$cr = “\r\n”;
// Create Closing Boundary
$bar = “–$boundary$cr”;
$data = $bar;
// Define Parameters
$data .= “Content-Disposition: form-data; name=“sessionId”” . $cr . $cr . $sessionId . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“catalogId”” . $cr . $cr . $catalogId->catalogId . $cr . $bar;
//$data .= “Content-Disposition: form-data; name=“destinationFolder”” . $cr . $cr . $UPLOADFOLDER . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“filename”” . $cr . $cr . $pFilename . $cr . $bar;
$data .= “Content-Disposition: form-data; name=”_ResourceType"" . $cr . $cr . $resourceType . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“action”” . $cr . $cr . “upload” . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“Filedata”; filename=”" . $item . “”" . $cr;
$data .= “Content-Type: application/octet-stream” . $cr . $cr;
$fileContents = file_get_contents("$directory/$item");
$data .= $fileContents;

// Initilize webrequest
URL = "http://" . _SERVER[‘HTTP_HOST’] . “:8090/FileTransfer/upload”;
$ch = curl_init($URL);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘POST’);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
‘Content-Type: multipart/form-data; boundary=’.$boundary,
‘Accept-Types: text/*’,
‘Connection: close’
)
);

// Submit request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$result = curl_exec ( $ch );

if ($result === FALSE) {
die(curl_error($ch));
}[/code]


#6

Trevor,

Why do you have destinationFolder commented out and where did you get the _ResourceType?

Matt


#7

Hi Matt,

The DestinationFolder is commented out, partly because I don’t know what it’s for exactly. I thought all assets were saved in a database, not in a folder. Is this some kind of temporary folder before it’s added to the DB?

_ResourceType was just an experiment to see if I could add assets with customdata fields. I’ve tried it with and without that addition and still no luck.

Best,

Trevor


#8

Trevor,

This next post is going to go into some details on how Portfolio works. If I tell you something that you already know, please don’t take offense, I’m just trying to be complete in my explanation.

There are three types of images that you will run into: Originals, Previews, and Thumbnails. Of these three, the Originals and the Previews are stored on disk.
Portfolio does have a database, but the primary function of that database is to keep track of asset locations (the originals), store thumbnails, and store metadata (fields). Previews are generated when an asset is added to Portfolio and stored in a fixed location. Thumbnails are generated and stored in the database. The Originals stay where they are.

One of Portfolio’s big features is called Autosync. Basically you specify a folder location and Portfolio will monitor this directory and add the contents to the Portfolio database. If any files are changed, or new files added, Portfolio will see these changes and make the proper updates to the database. The DestinationFolder usually will refer to an Autosync folder, or one of it’s subfolders.

(I should note that this doesn’t have to be the case. As long as the Destination folder is accessible by the server, It is a valid location and does not have to be an Autosync folder. But if this is going to be a Placeholder for an actual image at a later date, you should probably put it in an Autosync folder.)

Please let me know if you have anymore questions.
Matt


#9

Hi Matt,

I very much appreciate the explanation of the Portfolio server, it is very helpful. I’m trying to learn about the application while developing this script, so every bit helps.

Most likely due to my lack of understanding, I’m still having a couple problems with the script. I keep getting a HTTP 500 error when attempting to use the example upload code from the API site. I double checked that CURL is activated on the server, and it is, so I can’t see them figure out what’s going on.

[code]
UPLOADFOLDER = "::CHIPORTFOLIO2:C:Portfolio:wbmediadev files";
$item = “phthumb.jpg”;
$pFilename = “Placeholder-text”;
$directory = “C:\Images”;

// Create Boundary
$boundary = uniqid();
$cr = “\r\n”;

// Create Closing Boundary
$bar = “–$boundary$cr”;
$data = $bar;

// Define Parameters
$data .= “Content-Disposition: form-data; name=“sessionId”” . $cr . $cr . $sessionId . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“catalogId”” . $cr . $cr . $catalogId->catalogId . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“destinationFolder”” . $cr . $cr . $UPLOADFOLDER . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“filename”” . $cr . $cr . $pFilename . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“action”” . $cr . $cr . “upload” . $cr . $bar;
$data .= “Content-Disposition: form-data; name=“Filedata”; filename=”" . $item . “”" . $cr;
$data .= “Content-Type: application/octet-stream” . $cr . $cr;

$fileContents = file_get_contents(“C:\Images\phthumb.jpg”);
$data .= $fileContents;

// Initilize webrequest
$URL = “http://192.168.1.31:8090/FileTransfer/upload”;
$ch = curl_init($URL);

//custom
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘POST’);
//curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
‘Content-Type: multipart/form-data; boundary=’.$boundary,
‘Accept-Types: text/*’,
‘Connection: close’
)
);
// Submit request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$result = curl_exec ( $ch );[/code]

Best,

Trevor


#10

I was able to figure it out. I was not closing the request correctly with the boundary. It should be “$cr–$boundary–” which made it start working again. I don’t believe that bit is included in the PHP code example, just as an FYI.


#11

Trevor,

I’m glad you were able to figure it out.
I’ll take a look at the code sample and make sure it is correct.

Matt


#12

Trevor,

The code sample has been updated. It should read correctly now.

If you find any other typos, feel free to let us know.

Matt