• Set properties while creating docuıment

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #53027  by vngrshakan
 
I have metadata groups and properties and wanna set properties when im creating documents via RESTful api(document create or createSimple).
I cannot add properties from swagger collection. There are parameters here;
Code: Select all
 {
    "headers": {
      "additionalProp1": [
        "string"
      ],
      "additionalProp2": [
        "string"
      ],
      "additionalProp3": [
        "string"
      ]
    }
But its not working. Is there any way to set properties while creating documents?

OpenKm CE 6.3.9 version
 #53036  by jllort
 
Not possible, the OpenKM REST API does not have this method, you should create your own methods for this purpose. In the case of professional edition, the REST API has a method to extend with plugin architecture in case of CE must modify the current API code ( I suggest creating a new method instead of modifying the existing one ).
 #53318  by rpopenkm
 
I'm also getting the same issue while creating a document using restapi, didn't understand how to set the properties.
If you have any example please share it here.

openkm 6.3
windows 10
chrome browser
 #53328  by jllort
 
About what properties are talking about?
I suggest checkout the code and watch what really does the application ( because I suppose you think are doing things in background what really are not done ) -> should set the focus form this package https://github.com/openkm/document-mana ... s/endpoint
 #53347  by jllort
 
Swagger will help in basic REST API methods, but in the case of some POST like creating data with binary I do not suggest use it.

Take a look at the implementation of the create method:
https://github.com/openkm/document-mana ... e.java#L65

You should submit a POST form with type "multipart/form-data" where the name of the file is "content" and a Document serialized with the name "doc". I will share JAVA SDK implementation for better understanding:
Code: Select all
/**
 * create
 */
public Document createDocument(Document doc, InputStream is) throws IOException, UnsupportedMimeTypeException,
		FileSizeExceededException, UserQuotaExceededException, VirusDetectedException, ItemExistsException, PathNotFoundException,
		AccessDeniedException, RepositoryException, DatabaseException, ExtensionException, AutomationException, UnknowException,
		WebserviceException {
	Client client = getClient();
	try {
		client.setChunkedEncodingSize(1024); // To prevent heap error
		String uri = UriHelper.getUri(host, UriHelper.DOCUMENT_CREATE);
		FormDataMultiPart multiPart = new FormDataMultiPart();
		FormDataBodyPart filePart = new FormDataBodyPart("content", is, MediaType.APPLICATION_OCTET_STREAM_TYPE);
		multiPart.bodyPart(filePart);
		multiPart.field("doc", doc, MediaType.APPLICATION_XML_TYPE);
		WebResource resource = client.resource(uri);
		ClientResponse cResponse = resource.accept(MediaType.APPLICATION_XML).type(MediaType.MULTIPART_FORM_DATA_TYPE)
				.post(ClientResponse.class, multiPart);
		if (cResponse.getStatus() == Status.OK.getStatusCode()) {
			return cResponse.getEntity(Document.class);
		} else {
			String error = cResponse.getEntity(String.class);
			if (cResponse.getStatus() == Status.INTERNAL_SERVER_ERROR.getStatusCode()) {
				if (error.indexOf(":") > 0) {
					String className = error.substring(0, error.indexOf(":"));
					String msg = error.substring(error.indexOf(":") + 1);
					if (className.equals("IOException")) {
						throw new IOException(msg);
					} else if (className.equals("UnsupportedMimeTypeException")) {
						throw new UnsupportedMimeTypeException(msg);
					} else if (className.equals("FileSizeExceededException")) {
						throw new FileSizeExceededException(msg);
					} else if (className.equals("UserQuotaExceededException")) {
						throw new UserQuotaExceededException(msg);
					} else if (className.equals("VirusDetectedException")) {
						throw new VirusDetectedException(msg);
					} else if (className.equals("ItemExistsException")) {
						throw new ItemExistsException(msg);
					} else if (className.equals("PathNotFoundException")) {
						throw new PathNotFoundException(msg);
					} else if (className.equals("AccessDeniedException")) {
						throw new AccessDeniedException(msg);
					} else if (className.equals("RepositoryException")) {
						throw new RepositoryException(msg);
					} else if (className.equals("DatabaseException")) {
						throw new DatabaseException(msg);
					} else if (className.equals("ExtensionException")) {
						throw new ExtensionException(msg);
					} else if (className.equals("AutomationException")) {
						throw new AutomationException(msg);
					} else {
						throw new UnknowException(msg);
					}
				} else {
					throw new UnknowException("HTTP error code " + cResponse.getStatus() + ": " + error);
				}
			} else {
				throw new UnknowException("HTTP error code " + cResponse.getStatus() + ": " + error);
			}
		}
	} catch (ClientHandlerException e) {
		throw new WebserviceException(e);
	} finally {
		if (client != null) {
			client.destroy();
		}
	}
}

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.