Page 1 of 1

Set properties while creating docuıment

PostPosted:Fri Nov 19, 2021 7:18 am
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

Re: Set properties while creating docuıment

PostPosted:Sun Nov 21, 2021 9:33 am
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 ).

Re: Set properties while creating docuıment

PostPosted:Thu Mar 10, 2022 5:40 am
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

Re: Set properties while creating docuıment

PostPosted:Sat Mar 12, 2022 10:34 am
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

Re: Set properties while creating docuıment

PostPosted:Thu Mar 17, 2022 10:58 am
by rpopenkm
Thanks for your replay,

Actually I'm trying to create a document from openKm SwaggerUI, and couldn't understand what input should given.

On this link http://localhost:8080/OpenKM/services/r ... ice/create

what exactly should be given in body

Re: Set properties while creating docuıment

PostPosted:Sat Mar 19, 2022 9:15 am
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();
		}
	}
}

Re: Set properties while creating docuıment

PostPosted:Wed Mar 23, 2022 11:35 am
by rpopenkm
Thank You :-)