How to manage document.key correctly?

Hello @hasangok
Please let me describe it in detail.

“Every time the document is edited and saved, the key must be generated anew” – that means the final save of a file (when editing session is closed, i.e. all users left a file). By the way, if you are using forcesave feature, you should use the original (same) document.key.

Please check it out: ONLYOFFICE Api Documentation - Co-editing

Co-editing feature is possible due to using the same key only. When\how to change this parameter is your task as the integrator. For example, you can do it when editing session is closed or is started (file opening).

I’m also confused with this sentence: “Every time the document is edited and saved, the key must be generated anew”. In co-editing mode, document is saved in all keystrokes by all users, right? So I can’t decide when to update.

No, while editing session is in progress, all changes which were made by users are stored on document server side (database and cache). These changes are built to new file version and are sent to a storage only when editing session is over (or when forcesave feature is run).

Lets say 2 people are editing document with guid-0 key value, how can I detect they when all users quit the document so I can update key value to set guid-1 for newcomers?

Please check it out: ONLYOFFICE Api Documentation - Callback handler
“status 2” means that editing session is over and a file is ready for saving. That means all users left the file.