Basics

Lets base the examples on the following tree view:

Where a folder is denoted with a trailing "/", and prefixed with an ID number. Documents are listed with their ID and no trailing "/".

 Root/
    Accounting/
              Invoices/
                    INV 100
                    INV 101
                    INV 102
              Quotes/
                  QUO 200
                  QUO 200
     Human Resources/
                  Staff/
                      S001
                      S002
                      S003
                  Agencies/
                         AGN 500
                         AGN 501
                         AGN 502
                  Shortcut To Accounting
     Marketing/
            MAR 601
     Planning/
           Architecture/
                      ARC 700
           Road Map/
                      RDM 700
     Quality Assurance/
                    Version 3.0.0/
                                VER 800
                    README.txt
    Trash/
The following examples use PHP curl to access the REST API.
The base url for accessing the REST API is:
    $server_url = 'http://server.domain/ktwebservice/KTWebService.php?';

Login

Login and authenticate
    $url = $server_url.'method=login&password=admin&username=admin';
   
    // Push the url through curl
    $response = call_curl_function($url);
The response will have the following xml format:
<response>
        <status_code>
                0
        </status_code>
        <message>
        </message>
        <results>
                22a090a8f8e2ddacffd4be18cdc3589d
        </results>
</response>
Convert the xml to an array for use in php.
    $response = call_xml2array_function($response);
    $response = $response['response'];
On success the session id is returned as shown below and can be used for the functions called in the session.
        $session_id = $response['results'];
Using bash CURL:
    curl --location "https://renen151.knowledgetree.com/ktwebservice/KTWebService.php" \
                --data "username=[email protected]" \
                --data "password=XXXX" \
                --data "method=login"  > output.html 2> error.txt

Logout

Logging out will cause the session to end and the session id will be invalid.
    $url = $server_url.'method=logout&session_id='.$session_id;
    $response = call_curl_function($url);
The xml response will return a status_code of 0 to indicate a successful logout:
<response>
        <status_code>0</status_code>
</response>

Error Checking

After each call to the web service, it would be nice to check that no error has occured.
Convert the xml to an array for use in php.
    $response = call_xml2array_function($response);
    $response = $response['response'];
Check the status_code to determine if an error occurred. 0 indicates success. On failure the error message will be contained in the message tag.
    if($response['status_code'] != 0){
            return 'Error - authentication failed: '.$response['message'];
    }
All the examples that follow, should do an error check to validate that the actions were successful.