How to Retrieving the Dynamic Key

Dear OnlyOffice Support Team,

I hope this message finds you well.

I am currently working with OnlyOffice Document Server and I am looking to use the command-based API to trigger document saving operations. However, I am facing an issue regarding the dynamic key (which is required for the save command). I would appreciate your assistance with the following points:

  1. Retrieving the Dynamic Key:
    I want to invoke the save functionality using the command-based API. However, I am uncertain about how to retrieve the dynamic key that is needed as a parameter in the save command. This key is generated dynamically during the editing session, but I am not sure how to access it for external use.
  2. Available API for Retrieving the Key:
    Is there an existing API or endpoint that allows us to retrieve the dynamic key directly, without relying on the editor’s internal callback mechanism? Specifically, I am looking for a way to get the dynamic key for a document before attempting to save it programmatically.
  3. Challenges with Dynamic Key:
    Since the dynamic key is different for each save operation and can only be obtained after each session, it is not feasible to use the key generated at initialization (since it is valid only during the initial loading). I need a way to retrieve the current dynamic key for each save operation, ideally before initiating the save command.

Could you kindly provide guidance on how to retrieve the dynamic key in such cases or suggest an appropriate approach for using the command-based save API effectively?

Thank you in advance for your support. I look forward to your response.

Document Server version: Community Edition 8.0.1
Operating System: Linux node70 4.18.0-305.3.1.el8.x86_64 #1 SMP Tue Jun 1 16:14:33 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Best regards,

Hello @linford,
The key is sent to the callback whenever different operations occur:

The key received by the callback can be used to perform Command API’s forcesave

@DmitriiV This means I can also get the key from the onDocumentStateChange event, right?

Sorry for the delayed response.
No, the event by itself does not provide the document.key, but it can be retrieved from the callback as I mentioned

Hi @DmitriiV
"I understand your previous response, but it doesn’t quite meet my needs. I’m aiming to implement a feature where a third-party application can call an imperative interface to trigger the document saving function. However, the method you suggested, which relies on the ‘force save’ event to obtain the document key from the callback, creates a conflict with my requirement.

Essentially, I need a way to directly retrieve the document key when initiating the save operation through an imperative call, rather than relying on an asynchronous event callback.

Therefore, I have two key questions:

  1. Are there alternative methods to obtain the document key in this scenario?
  2. If not, are there any other approaches that would allow me to achieve my goal of enabling third-party applications to initiate document saves and obtain the corresponding document keys through an imperative interface?

I’m looking for a solution that provides a more direct and synchronous way to handle this process."

The key for the documents is generated on integrator’s side, so it is the integrator who stores the key, it can be retrieved on the integrator’s side, it has nothing to do with the Document Server itself.
Also, Asc.plugin.info method of plugins can be used to retrieve the key -
asc.plugin.info

The documentId field will include document key