|
/SW/business/KnowledgeTree:
Metadata and the KnowledgeTree REST API
The only way I have personally been able to get this working is by patching KnowledgeTree. The problem is that there is a function get_packed_metadata in ktapi/KTAPIDocument.inc.php that expects to receive metadata in the form of an array. There is no way to pass an array through a URL as a POST parameter using PHP (at least, none that I have yet found....)
What I have found is that the PHP serialize() / unserialize() functions are meant to get this job done: serialize() the array before passing, unserialize() it after passing, and then process the array on the receiving end. So I have added this chunk of code to the top of function get_packed_metadata in ktapi/KTAPIDocument.inc.php:
if (!is_array($metadata)) { $metadata = unserialize($metadata); }
And then if I serialize my metadata array before sending it into the API, everything works. The exact structure of the metadata array was also a bit of a hard-won mystery, so I will reproduce below an actual working metadata update snippet of code:
status_code != 0 ){ echo 'Error - authentication failed: ' . $xml->message; } else { $session_id = $xml->results; echo "Login successful, session ID = " . $session_id; } // *********************************** // Update document metadata // *********************************** $metadata = array( array( "fieldset" => "Tag Cloud", "fields" => array( array( "name" => "Tag", "value" => "Tag name from API call" ) ) ) ); $metadata = serialize($metadata); $postfields = "method=update_document_metadata&session_id=$session_id&document_id=36&metadata=$metadata"; $response = curlPost($url, $postfields); $xml = new SimpleXMLElement($response); echo " Update document metadata:
"; if( $xml->status_code != 0 ){ echo 'Error - get_document_metadata failed: ' . $xml->message; } else { echo 'Metadata updated!!'; }
I have posted on this subject to both the KnowledgeTree forum[1] and the issue tracker[2], and received just about zero response.
I have a working example of a file upload followed by an add-document-with-metadata API operation, if anyone is interested in seeing that.
[1] http://forums.knowledgetree.com/viewtopic.php?f=10&t=14291&p=31392#p31392
[2] http://issues.knowledgetree.com/browse/WSA-169
posted at: 23:03 | path: /SW/business/KnowledgeTree | permanent link to this entry