Repository samples

Methods

getRootFolder

Description:

MethodReturn valuesDescription

getRootFolder()

Folder

Return the object Folder of node "/okm:root"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getRootFolder()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getTrashFolder

Description:

MethodReturn valuesDescription

getTrashFolder()

Folder

Returns the object Folder of node "/okm:trash/{userId}"

The returned folder will be the user trash folder.

For example if the method is executed by "okmAdmin" user then the folder returned will be "/okm:trash/okmAdmin".

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getTrashFolder()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getTrashFolderBase

Description:

MethodReturn valuesDescription

getTrashFolderBase()

Folder

Returns the object Folder of node "/okm:trash"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getTrashFolderBase()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getTemplatesFolder

Description:

MethodReturn valuesDescription

getTemplatesFolder()

Folder

Returns the object Folder of node "/okm:templates"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getTemplatesFolder()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPersonalFolder

Description:

MethodReturn valuesDescription

getPersonalFolder()

Folder

Returns the object Folder of node "/okm:personal/{userId}"

The returned folder will be the user personal folder.

For example, if the method is executed by "okmAdmin" user then the folder returned will be "/okm:personal/okmAdmin".

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getPersonalFolder()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPersonalFolderBase

Description:

MethodReturn valuesDescription

getPersonalFolderBase()

Folder

Return the object Folder of node "/okm:personal"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getPersonalFolderBase()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailFolder

Description:

MethodReturn valuesDescription

getMailFolder()

Folder

Returns the object Folder of node "/okm:mail/{userId}"

The returned folder will be the user mail folder.

For example if the method is executed by "okmAdmin" user then the folder returned will be "/okm:mail/okmAdmin".

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getMailFolder()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getMailFolderBase

Description:

MethodReturn valuesDescription

getMailFolderBase()

Folder

Returns the object Folder of node "/okm:mail"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getMailFolderBase()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getThesaurusFolder

Description:

MethodReturn valuesDescription

getThesaurusFolder()

Folder

Returns the object Folder of node "/okm:thesaurus"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getThesaurusFolder()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getCategoriesFolder

Description:

MethodReturn valuesDescription

getCategoriesFolder()

Folder

Returns the object Folder of node "/okm:categories"

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getCategoriesFolder()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

purgeTrash

Description:

MethodReturn valuesDescription

purgeTrash()

void

Definitively removes from repository all nodes into "/okm:trash/{userId}"

For example, if the method is executed by "okmAdmin" user then the purged trash will be "/okm:trash/okmAdmin".

When a node is purged only will be able to be restored from a previously repository backup. The purge action removes the node definitely from the repository.

 

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { ws.purgeTrash(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getUpdateMessage

Description:

MethodReturn valuesDescription

getUpdateMessage()

String

Retrieves a message when a new OpenKM release is available.

There's an official OpenKM update message service available which is based on your local OpenKM version. 

The most common message is that a new OpenKM version has been released.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8180/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getUpdateMessage()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getRepositoryUuid

Description:

MethodReturn valuesDescription

getRepositoryUuid()

String

Retrieves installation unique identifier.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getRepositoryUuid()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

hasNode

Description:

MethodReturn valuesDescription

hasNode(String nodeId)

Boolean

Returns a node that indicates if a node exists or not.
The value of the parameter nodeId can be a valid UUID or path.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine("Exists node:" + ws.hasNode("064ff51a-b815-4f48-a096-b4946876784f")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getNodePath

Description:

MethodReturn valuesDescription

getNodePath(String uuid)

String

Converts a node UUID to the path.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getNodePath("e339f14b-4d3a-489c-91d3-05e4575709d2")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getNodeUuid

Description:

MethodReturn valuesDescription

getNodeUuid(String path)

String

Convert node path to UUID.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getNodeUuid("/okm:root/tmp")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getAppVersion

Description:

MethodReturn valuesDescription

getAppVersion()

AppVersion

Return information about OpenKM version.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getAppVersion()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

copyAttributes

Description:

MethodReturn valuesDescription

copyAttributes(String nodeId, String dstId, boolean categories, boolean keywords, boolean propertyGroups, boolean notes,
            boolean wiki)

void

Copy attributes from a node to other.

The values of the dstId parameter should be a node UUID or path.

  • When the category parameter is true the original values of the categories will be copied.
  • When the keywords parameter is true the original values of the keywords will be copied.
  • When the property groups parameter is true the original values of the metadata groups will be copied.
  • When the notes parameter is true the original values of the notes will be copied.
  • When the wiki parameter is true the original values of the wiki will be copied.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { ws.copyAttributes("/okm:root/invoice.pdf", "/okm:root/cloned_invoice.pdf", true, true, true, true, true); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

executeScript

Description:

MethodReturn valuesDescription

executeScript(FileStream fs)

ScriptExecutionResult

Execute an script.

The local script - test.bsh - used in the sample below:

import com.openkm.bean.*;
import com.openkm.api.*;

for (Folder fld : OKMFolder.getInstance().getChildren(null,"/okm:root")) {
    print(fld+"\n");
}
// Some value can also be returned as string
return "some result";

This action can only be done by a superuser ( user with ROLE_ADMIN ).

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using System.IO;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { FileStream fs = new FileStream("E:\\test.bsh", FileMode.Open); ScriptExecutionResult result = ws.executeScript(fs); System.Console.WriteLine(result.result); System.Console.WriteLine(result.stdout);
                 if (!result.stderr.Equals("")) { System.Console.WriteLine("Error happened"); System.Console.WriteLine(result.stderr); }
                 fs.Dispose(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

executeSqlQuery

Description:

MethodReturn valuesDescription

executeSqlQuery(FileStream fs)

SqlQueryResults

Executes SQL sentences.

The test.sql script used in the sample below:

SELECT NBS_UUID, NBS_NAME FROM OKM_NODE_BASE LIMIT 10;

The SQL script can only contain a single SQL sentence.

This action can only be done by a superuser ( user with ROLE_ADMIN ).

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using System.IO;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { FileStream fs = new FileStream("E:\\test.sql", FileMode.Open); SqlQueryResults result = ws.executeSqlQuery(fs);
                 foreach (SqlQueryResultColumns row in result.sqlQueryResults) { System.Console.WriteLine("uuid:" + row.sqlQueryResultColumn[0] + ", name:" + row.sqlQueryResultColumn[1]); }
                 fs.Dispose(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

executeHqlQuery

Description:

MethodReturn valuesDescription

executeHqlQuery(FileStream fs)

HqlQueryResults

Execute HQL sentences.

The test.sql script used in the sample below:

SELECT uuid, name from NodeBase where name = 'okm:root';

The HQL script can only contain a single HQL sentence.

This action can only be done by a superuser ( user with ROLE_ADMIN ).

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using System.IO;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);            
            try
            {
                 FileStream fs = new FileStream(@"C:\Desktop\test.sql", FileMode.Open);
                 HqlQueryResults result = ws.executeHqlQuery(fs);

                 foreach (HqlQueryResultColumns row in result.hqlQueryResults)
                 {
                     foreach (string column in row.hqlQueryResultColumn)
                     {
                         System.Console.WriteLine(column);
                     }
                 }

                 fs.Dispose();
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}

getTranslations

Description:

MethodReturn valuesDescription

getTranslations(String lang, String module)

Dictionary<String, String>

Retrieves the translations of a module into a Map of values

The OpenKM translations tables can be used to retrieve actually OpenKM translations or create your own translations ( insert values into the new module ).

By default modules values are :

  • frontend ( used by default OpenKM UI ).
  • extension ( used by OpenKM extension UI ).
  • mobile ( used by OpenKM mobile UI ).

Example to add a new Translation module :

SQL values to be executed from Database query view:

DELETE FROM OKM_TRANSLATION WHERE TR_LANGUAGE='en-GB' and TR_MODULE='doc';
INSERT INTO OKM_TRANSLATION (TR_MODULE, TR_KEY, TR_TEXT, TR_LANGUAGE) VALUES ('doc', 'document.generator.title','Document generator', 'en-GB');
INSERT INTO OKM_TRANSLATION (TR_MODULE, TR_KEY, TR_TEXT, TR_LANGUAGE) VALUES ('doc', 'document.generator.logout','Logout', 'en-GB');

The code then should be:

Dictionary<String, String> translations = ws.getTranslations("en-GB", "doc");

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { Dictionary<string,string>translations = ws.getTranslations("en-GB", "frontend"); foreach (KeyValuePair<string, string> kvp in translations) { Console.WriteLine("key:{0},with translation:{1}", kvp.Key, kvp.Value); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getConfiguration

Description:

MethodReturn valuesDescription

getConfiguration(String key)

Configuration

Retrieve the value of a configuration parameter.

If your OpenKM version has the configuration parameter named "webservices.visible.properties", will be restricted for non Administrator users what parameters are accessible. That means any non Administrator use who will try accessing across the webservices to configuration parameters not set into the list of values of "webservices.visible.properties" will get an access denied exception.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
            try
            {
                Configuration configuration = ws.getConfiguration("system.ocr");
                System.Console.WriteLine(configuration);
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}

executePlugin

Description:

MethodReturn valuesDescription

executePlugin(String className, Dictionary<String, String> parameters, FileStream fs)

String

Return the String value of execution of a class which implements RestPlugin.

  • The "className" value must be the canonical class name of a class which implements RestPlugin interface.
  • The "parameters" map are values what will be used by class set in className.
  • The "fs" stream allow uploading a document.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
            try
            {
                Dictionary<String, String> parameters = new Dictionary<string, string>();
                parameters.Add("param1", "value1");
                parameters.Add("param2", "value2");
                FileStream fileStream = new FileStream(@"C:\Desktop\img.png", FileMode.Open);
                String value = (String)ws.executePlugin("com.openkm.plugin.rest.TestRestPlugin", parameters, fileStream);
                System.Console.WriteLine(value);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
        }
    }
}

 getChangeLog

Description:

MethodReturn valuesDescription

getChangeLog(String nodePath, DateTime modificationsFrom)

List<ChangeLogged>

Return the list of changes in some path and subfolders.

  • The method is used by the desktop synchronization application for retrieving the changes.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
            try
            {
                List<ChangeLogged> changeLoggedList = ws.getChangeLog("/okm:root/test", DateTime.Now);
                foreach (var cl in changeLoggedList)
                {
                    System.Console.WriteLine(cl.toString());
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
        }
    }
}

getServerTime()

Description:

MethodReturn valuesDescription

getServerTime()

String

Return the current server time.

The server time returned format is ISO8601

The method is used by desktop synchronization application for retrieving the changes

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;

namespace OKMRest
{
    public class Program
    {
        static void Main(string[] args)
        {
            String host = "http://localhost:8080/OpenKM";
            String username = "okmAdmin";
            String password = "admin";
            OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
             try { System.Console.WriteLine(ws.getServerTime()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }