KnowledgeTree Community Forums

Skip to content


Advanced search
  • Board index ‹ KnowledgeTree Users ‹ Using KnowledgeTree
  • Change font size
  • Print view
  • FAQ
  • Register
  • Login

Examples of KTAPI methods

Questions and discussion around the KnowledgeTree user experience: usability, user interface and functionality (KnowledgeTree 3.x specific)
Post a reply
7 posts • Page 1 of 1

Examples of KTAPI methods

Postby omermx2 » Thu Jun 25, 2009 11:59 am

Hi, I've been looking through API documentation and it seems to be a little thin on the ground. I was wondering if anyone had an example in PHP where they have called: add_document_with_metadata.

I'm unclear what some of the variables that the function expects as arguments should be. For example $metadata, does this have to be a fieldset, string of text etc. Where do I get values for $sig_username = '', $sig_password = ''? I Was thinking this information is probably available in the session variable, but again there's very little documentation on this.

To give a bigger picture, I want to call this method once a form has been submitted and a file has been created - the metadata is crucial in order for the document to be retrieved.

Any hints or help much appreciated.
omermx2
 
Posts: 8
Joined: Tue Jun 16, 2009 3:03 pm
Top

Re: Examples of KTAPI methods

Postby omermx2 » Fri Jun 26, 2009 11:20 pm

Well for anyone that might have been struggling with this, here's a code snippet that might help:

Code: Select all

<?php

require_once('ktapi/ktapi.inc.php');

/* Create an instance of KTAPI */
$kt = new KTAPI();

/* Create a session */
$kt->start_session("admin", "admin");

/* Choose the folder you want to upload the file to */
$folder = $kt->get_folder_by_name("Folder Name");

/* Use the add_document method of the KTFolder class to upload the file, returns KTDocument object if successful and a PEAR error if not, the documentid of the newly uploaded file is a field of the returned KTDocument object. Use $result->get_documentid(); to get the document id just uploaded.
*/
$result = $folder->add_document("Document Title", "Filename in KnowledgeTree", "Document Type", "Location of file to be uploaded");





omermx2
 
Posts: 8
Joined: Tue Jun 16, 2009 3:03 pm
Top

Re: Examples of KTAPI methods

Postby Paul Barrett » Fri Jul 10, 2009 7:42 am

Hi

Regarding $sig_username and $sig_password, these are both for the API electronic signatures functionality. This functionality only exists in the commercial edition and is switched off by default. Unless you have it switched on you can safely ignore those values.

If you do have API electronic signatures switched on, these values should be the same username and password with which you authenticated your session. It is simply an extra level of validation on certain write actions. You would also then need to supply the $reason value on all calls requiring the signature authentication values, as this is also required for electronic signature recording.

Paul
Last edited by Paul Barrett on Fri Jul 10, 2009 11:26 am, edited 1 time in total.
Paul Barrett
KnowledgeTree Team Member
 
Posts: 47
Joined: Fri Jul 10, 2009 7:34 am
Top

Re: Examples of KTAPI methods

Postby Paul Barrett » Fri Jul 10, 2009 11:25 am

Extending from code I found in another post

http://forums.knowledgetree.com/viewtopic.php?f=10&t=14291&p=31392&hilit=add_document_with_metadata#p31392

I have tested this example code (only showing the metadata array and the ktapi call):

Code: Select all
$metadata = array(array("fieldset" => "Tag Cloud",
                        "fields" => array(
                            array( "name" => "Tag",
                                   "value" => "Tag name from API call"
                            )
                        )
                  ),
                  array("fieldset" => "General Information",
                        "fields" => array(
                            array( "name" => "Document Author",
                                    "value" => "Author name from API call"
                             ),
                             array( "name" => "Category",
                                    "value" => "Category name from API call"
                             ),
                             array( "name" => "Media Type",
                                    "value" => "Media Type name from API call"
                             )
                        )
                     )
                  );
$result = $ktapi->add_document_with_metadata($folder_id,  $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata);


Currently when I add a document through the web interface I get offered these Categories:

Administrative
Financial
Legal
Miscellaneous
Sales
Technical

and these Media Types:

Audio
Image
Text
Video
Paul Barrett
KnowledgeTree Team Member
 
Posts: 47
Joined: Fri Jul 10, 2009 7:34 am
Top

Re: Examples of KTAPI methods

Postby x2002ugp » Mon Jun 28, 2010 11:55 pm

For the love of all things holy on this planet, someone please help me with this...

I've spent all day trying to get the "add_document_with_metadata" functionality to work, to no avail. Could someone please scan my code quickly to point me in the right direction?

This code does not give me an error when I run it, but it does not create any document:

Code: Select all
<?php

require_once('/usr/share/knowledgetree-ce/ktapi/ktapi.inc.php');

$ktapi = new KTAPI();

$response = $ktapi->start_session('admin','admin');
if (PEAR::isError($response))
{
        print $response->getMessage();
        exit;
}


//Empty arrays - just proof of concept
$metadata = array();
$sysdata = array();

$result = $ktapi->add_document_with_metadata(1, "Document Title", "Filename in KnowledgeTree", "Document Type", "/home/test/dummy.txt", $metadata, $sysdata);

if (PEAR::isError($result))
{
        print $result->getMessage();
        exit;
}

$ktapi->logout();

?>


Here is an example of simple "add_document" code which DOES work...

Code: Select all
<?php

require_once('/usr/share/knowledgetree-ce/ktapi/ktapi.inc.php');

$ktapi = new KTAPI();

$response = $ktapi->start_session('admin','admin');
if (PEAR::isError($response))
{
        print $response->getMessage();
        exit;
}


$root = $ktapi->get_root_folder();

$result = $root->add_document("Document Title", "Filename in KnowledgeTree", "Document Type", "/home/test/dummy.txt");

if (PEAR::isError($result))
{
        print $result->getMessage();
        exit;
}

$ktapi->logout();
?>


x2002ugp
 
Posts: 5
Joined: Wed Jun 23, 2010 7:10 pm
Top

Re: Examples of KTAPI methods

Postby x2002ugp » Mon Jul 19, 2010 5:00 pm

Hrmm, I'm still trying to figure this out...

I'm positive that it's got to be a syntax issue.

If someone could just quickly review the above posted code, I'm sure you could spot my error within minutes...

Any help would be GREATLY appreciated!
x2002ugp
 
Posts: 5
Joined: Wed Jun 23, 2010 7:10 pm
Top

Re: Examples of KTAPI methods

Postby Paul Barrett » Thu Jul 29, 2010 1:28 pm

Firstly, you may want to add this line to your code after the ktapi call:

echo '<pre>' . print_r($result, true) . '</pre>';

This will print out the actual result, which is only a PEAR error on an unexpected failure conditions. Known failure conditions will be indicated within the response from ktapi, and this response will be an array when using ktapi directly in the code as is happening here. You are not seeing an error because you are only checking for PEAR errors and not checking the ktapi response for its own status messages.

In this printout, you will see something called 'status_code': 1 is failure, 0 is success. If the status_code is 1 you should also see an element called 'message' which tells you why the call failed.

Looking at the code inside ktapi, add_document_with_metadata calls add_document first and then deals with the metadata independently, so the actual document add is done by the same code whichever function you call. I cannot understand why one would work for you and not the other. My testing fails on both with the following message:

"Invalid temporary file: c:/tmp/dummy.txt. Not compatible with paul/uploads."

This is telling me that the file is not found in that location. The file needs to be placed in the KnowledgeTree uploads directory prior to calling either function, and this uploads directory must match that configured for your system. In your installation I would say this is likely to be /usr/share/knowledgetree-ce/var/uploads.

This is the same way the regular interface works (although it is hidden from the user) - when you upload via the regular upload page, the first page submission uploads the document into the uploads folder, the second, where you add metadata if you wish to, then performs the step which is performed by these ktapi functions, using that uploaded file.

Life is still very busy for me but if you can try that printout and post back here how it goes (or message me privately with the results) as well as see whether placing the file first in your uploads directory solves the problem, this should place us closer to a solution, and I will watch this thread and try to reply asap once we know more.
Paul Barrett
KnowledgeTree Team Member
 
Posts: 47
Joined: Fri Jul 10, 2009 7:34 am
Top


Post a reply
7 posts • Page 1 of 1

Return to Using KnowledgeTree

Who is online

Users browsing this forum: No registered users and 1 guest

  • Board index
  • The team • Delete all board cookies • All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Translated by phpBB.fr © 2007, 2008 phpBB.fr
SourceForge.net Logo
Document Management Software
File Sharing  |   Sales Document Management  |   Deal Rooms  |   Accounting Document Management  |   HR Document Management