Co-edit Document
Zoho Office Integrator supports real-time document collaboration. This means several users can open a particular document at the same time, with everyone being able to contribute to the document in real time.
With built-in collaboration features, businesses can enhance user productivity, foster teamwork, and cooperation. When a document is shared with others, teams can work together in the same instance - so when someone makes a change, the document is updated for everyone to see. Also, the integrated Zoho Chat application allows each user to communicate in real time and see who else is available.
Purpose
To co-edit or collaborate on a document in Zoho Writer in real-time.
HTTP Request URL
https://{api.office-integrator_domain}/writer/officeapi/v1/documents
Request Parameters
Parameter | Value | Description |
Mandatory Parameter | ||
apikey | 423s***** | Uniquely identifies the web application in which the Writer editor is integrated. |
document or url | File or String | Method of providing the input file depending on its location. Note: You can also upload password protected files and edit them. As of now, it is supported only for docx file format. |
callback_settings | { "save_format":"zdoc", "save_url":<Your Save URL>, "http_method_type": "post", "retries": <Integer>, "timeout": <Integer>, "save_url_params": { .... } } | Using this param, you will be able to specify the following; save_format -> Specify the output format in which the edited document needs to be saved. save_url -> Provide your server location to which the latest content needs to be pushed back when the 'Save' is performed. The below key values are optional; http_method_type -> Specify the http method in which the save request has to be triggered. retries -> Specify the number of retries required when the 'Save' fails. timeout -> Specify the timeout for the given saveurl. save_url_params -> To customize the output parameters in which the document details will be pushed from our end.
|
Optional Parameters - Editor Customization | ||
document_defaults | { "track_changes": "enabled", "language":"en-US", "date_format":"MM/DD/YY" } | Set document defaults such as custom date format and enable/disable track changes. You can also set a desired language for the document. The document language set will affect the following;
|
editor_settings | { "unit":"in", "language":"en", "view":"webview" } | Set Editor preferences like Unit in inch/mm, interface language and view as pageview/webview for new documents. |
permissions | { "document.export":true, "document.print":true, "document.edit":true, "review.changes.resolve":true, "review.comment":true, "collab.chat":true "document.pausecollaboration":false, "document.fill":true } | Define document permissions for the users. |
document_info | { "document_name":"New", "document_id":"1349" } | Set a unique id and specify display name of the new document. |
user_info | { "user_id":"1973", "display_name":"Ken" } | Identify the user in the document with "user_id" and "display_name". |
ui_options | { "save_button":"show", "chat_panel":"show", "dark_mode":"show", "file_menu":"show" } | Specify whether the "Save button", "Chat panel", "File menu" and the "Dark mode" option needs to be shown or hidden. |
Note
Editor customization parameters and their values are case-sensitive.
Editor Customization Parameters
document_defaults
Parameter | Type | Possible Values | Default Value |
track_changes | boolean | enabled / disabled | disabled |
language | string | en-US / af / bn / ca / cs / et and more... | en-US |
date_format | string | For example: EEEE, MMMM DD, YYYY at HH:mm Output: Monday, July 15, 2024 at 21:06 | Date format will be displayed based on the document language value. |
editor_settings
Parameter | Type | Possible Values | Default Value |
unit | string | in/mm | in (inch) |
language | string | en / de / es / fr / ja / nl more... | en |
view | string | webview / pageview | pageview ("view" param is applicable to new documents only) |
permissions
Parameter | Type | Possible Values | Default Value | Description |
document.export | boolean | true / false | true | To enable or disable document download option |
document.print | boolean | true / false | true | To enable or disable document print option |
document.edit | boolean | true / false | false | Provide option to allow edit access to the document |
review.comment | boolean | true / false | false | Provide option to manage comments |
review.changes.resolve | boolean | true / false | false | Provide option to resolve track changes |
collab.chat | boolean | true / false | true | To enable or disable chat panel for the collaborators |
document.pausecollaboration | boolean | true / false | false | Provide option to manage collaboration |
document.fill | boolean | true / false | true | Provide option to allow edit access for the fillable fields |
callback_settings
Parameter | Type | Possible Values | Default Value |
Mandatory Keys | |||
save_format | string | zdoc / doc / docx / odt / html / pdf and more ... | zdoc |
save_url | string | URL - Maximum length -> 65535 | URL |
Optional Keys | |||
save_url_params | JSON |
| |
http_method_type | string | post / put | post |
retries | integer | 0 to 3 | 0 |
timeout | integer | 1 to 120000 milliseconds | 120000 |
document_info
Parameter | Type | Possible Values | Default Value |
document_id | string | 13as49rf | |
document_name | string | Sample | Untitled |
user_info
Parameter | Type | Possible Values | Default Value |
user_id | integer | 1973345 | |
display_name | string | Ken/James/Adam | Guest |
ui_options
Parameter | Type | Possible Values | Default Value |
save_button | string | show/hide | show |
chat_panel | string | show/hide | show |
dark_mode | string | show/hide | show |
file_menu | string | show/hide | show |
Co-edit Document - Error Codes
Code | Description |
1831 | Error occurred. Parameter value is either incorrect or invalid. |
1852 | File format you're trying to import is not supported. |
1868 | Invalid parameter name for uploaded content. |
For a full list of error handling cases in Co-edit Document, refer here.
Note:
To open a document in Co-view or collab view mode, please set 'document.edit:false' in "permissions" parameter section.
save_url usage:
Zoho Office Integrator allows partners and businesses to save the document content back to their specified storage server through "save_url" method.
A save_url is a publicly accessible web URL/Service to which Zoho will push the updated document content from Writer editor to the partner's server.
In order to use the save_url method, partners should fulfill the below requirements:
- Partner's remote servers need to expose one of their ports - port 443 (https) or port 80 (http) - from their location, for Zoho Writer to push the data back.
- The save_url value specified in the HTTPS/HTTP POST request should be a proper domain name and publicly accessible over the web. Example: https://yourdomain.com/save.php
save_url_params usage:
By default, when the 'Save' is performed, we will be pushing back the information with the following key names:
Key Name | Type | Description |
content | File | Document content will be pushed back in the form of bytes. |
filename | String | Document name |
format | String | Specifies the format in which the document has been exported. |
If you wish to customize the above key names that you need to send back during save call, you can make use of the 'save_url_params' key inside 'callback_settings' parameter.
Once the 'save_url_params' key is configured, only the key values defined inside will be pushed back to your server. The default key names (like filename and format) will not be included. To include them, you need to define your own keys for format, filename and session_id by using the system variable $format, $filename and $session_id respectively.
If the 'save_url_params' is passed as an empty JSON or the system variable $content is not configured, the document bytes will be pushed back with the multipart name 'content' by default.
Syntax:
"save_url_params": {
<custom_content_key>: $content,
<custom_format_key>: $format,
<custom_filename_key>: $filename,
<custom_sessionId_key>: $session_id,
<additional_user_key>: <value>,
<additional_user_key>: <value>,
....
<additional_user_key>: <value>
},
Example:
"save_url_params": {
file: $content,
extension: $format,
document_name: $filename,
session_id: $session_id,
<additional_user_key>: <value>,
<additional_user_key>: <value>
},
In the above example, the document bytes will be pushed back in the multipart name 'file', document format in the key name 'extension', document filename in the key name 'document_name' and document session id in the key name 'session_id'.
Sample Request
Copiedcurl -X POST \
https://api.office-integrator.com/writer/officeapi/v1/documents \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F apikey=423s***** \
-F document=@/Users/username/Documents/Sample.docx \
-F 'document_defaults={"track_changes":"enabled","language":"en-US","date_format":"MM/DD/YY"}' \
-F 'editor_settings={'\''unit'\'':'\''in'\'','\''language'\'':'\''en'\'','\''view'\'':'\''webview'\''}' \
-F 'permissions={'\''document.export'\'':true,'\''document.print'\'':true,'\''document.edit'\'':true,'\''review.changes.resolve'\'':true,'\''review.comment'\'':true,'\''collab.chat'\'':true,'\''document.pausecollaboration'\'':false,'\''document.fill'\'':true }' \
-F 'callback_settings={'\''save_format'\'':'\''zdoc'\'','\''save_url'\'':'\''https://domain.com/save.php/'\''}' \
-F 'document_info={'\''document_name'\'':'\''New'\'', '\''document_id'\'':1349}' \
-F 'user_info={'\''user_id'\'':'\''1973'\'','\''display_name'\'':'\''Ken'\''}' \
-F 'ui_options={"save_button":"show","chat_panel":"show","dark_mode":"hide","file_menu":"show"}'
Copiedconst Levels = require("zoi-nodejs-sdk/routes/logger/logger").Levels;
const Constants = require("zoi-nodejs-sdk/utils/util/constants").Constants;
const APIKey = require("zoi-nodejs-sdk/models/authenticator/apikey").APIKey;
const Environment = require("zoi-nodejs-sdk/routes/dc/environment").Environment;
const LogBuilder = require("zoi-nodejs-sdk/routes/logger/log_builder").LogBuilder;
const UserSignature = require("zoi-nodejs-sdk/routes/user_signature").UserSignature;
const InitializeBuilder = require("zoi-nodejs-sdk/routes/initialize_builder").InitializeBuilder;
const UiOptions = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/ui_options").UiOptions;
const UserInfo = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/user_info").UserInfo;
const DocumentInfo = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/document_info").DocumentInfo;
const DocumentDefaults = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/document_defaults").DocumentDefaults;
const CallbackSettings = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/callback_settings").CallbackSettings;
const CreateDocumentResponse = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/create_document_response").CreateDocumentResponse;
const CreateDocumentParameters = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/create_document_parameters").CreateDocumentParameters;
const InvaildConfigurationException = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/invaild_configuration_exception").InvaildConfigurationException;
const OfficeIntegratorSDKOperations = require("zoi-nodejs-sdk/core/com/zoho//officeintegrator/office_integrator_sdk/office_integrator_sdk_operations").OfficeIntegratorSDKOperations;
class CoEditDocument {
//Include zoi-nodejs-sdk package in your package json and the execute this code.
static async initializeSdk() {
let user = new UserSignature("john@zylker.com");
let environment = new Environment("https://api.office-integrator.com", null, null);
let apikey = new APIKey("2ae438cf864488657cc9754a27daa480", Constants.PARAMS);
let logger = new LogBuilder()
.level(Levels.INFO)
.filePath("./app.log")
.build();
let initialize = await new InitializeBuilder();
await initialize.user(user).environment(environment).token(apikey).logger(logger).initialize();
console.log("\nSDK initialized successfully.");
}
static async execute() {
//Initializing SDK once is enough. Calling here since code sample will be tested standalone.
//You can place SDK initializer code in your application and call once while your application start-up.
await this.initializeSdk();
try {
var sdkOperations = new OfficeIntegratorSDKOperations();
var createDocumentParameters = new CreateDocumentParameters();
var documentInfo = new DocumentInfo();
//To collaborate in existing document, providing the document id (e.g: 1000) alone is enough.
//Note: Make sure the document already exist in Zoho server (for below given document id).
//Even if the document is added to this request, if document exist in Zoho server for given document id, then session will be create for the document which already exist in Zoho.
documentInfo.setDocumentId("1000");
createDocumentParameters.setDocumentInfo(documentInfo);
var userInfo = new UserInfo();
userInfo.setUserId("1000");
userInfo.setDisplayName("Amelia");
createDocumentParameters.setUserInfo(userInfo);
var documentDefaults = new DocumentDefaults();
documentDefaults.setTrackChanges("enabled");
createDocumentParameters.setDocumentDefaults(documentDefaults);
var uiOptions = new UiOptions();
uiOptions.setDarkMode("show");
uiOptions.setFileMenu("show");
uiOptions.setSaveButton("show");
uiOptions.setChatPanel("show");
createDocumentParameters.setUiOptions(uiOptions);
var permissions = new Map();
permissions.set("collab.chat", false);
permissions.set("document.edit", true);
permissions.set("document.fill", false);
permissions.set("document.export", true);
permissions.set("document.print", false);
permissions.set("review.comment", false);
permissions.set("review.changes.resolve", false);
permissions.set("document.pausecollaboration", false);
createDocumentParameters.setPermissions(permissions);
var callbackSettings = new CallbackSettings();
var saveUrlParams = new Map();
saveUrlParams.set("auth_token", "1234");
saveUrlParams.set("id", "123131");
callbackSettings.setSaveUrlParams(saveUrlParams);
callbackSettings.setRetries(1);
callbackSettings.setSaveFormat("docx");
callbackSettings.setHttpMethodType("post");
callbackSettings.setTimeout(100000);
callbackSettings.setSaveUrl("https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286");
createDocumentParameters.setCallbackSettings(callbackSettings);
var responseObject = await sdkOperations.createDocument(createDocumentParameters);
if(responseObject != null) {
//Get the status code from response
console.log("\nStatus Code: " + responseObject.statusCode);
//Get the api response object from responseObject
let writerResponseObject = responseObject.object;
if(writerResponseObject != null){
//Check if expected CreateDocumentResponse instance is received
if(writerResponseObject instanceof CreateDocumentResponse){
console.log("\nDocument ID - " + writerResponseObject.getDocumentId());
console.log("\nDocument session ID - " + writerResponseObject.getSessionId());
console.log("\nDocument session URL - " + writerResponseObject.getDocumentUrl());
console.log("\nDocument save URL - " + writerResponseObject.getSaveUrl());
console.log("\nDocument delete URL - " + writerResponseObject.getDocumentDeleteUrl());
console.log("\nDocument session delete URL - " + writerResponseObject.getSessionDeleteUrl());
} else if (writerResponseObject instanceof InvaildConfigurationException) {
console.log("\nInvalid configuration exception. Exception json - ", writerResponseObject);
} else {
console.log("\nRequest not completed successfullly");
}
}
}
} catch (error) {
console.log("\nException while running sample code", error);
}
}
}
CoEditDocument.execute();
Sample Response
Copied{
"document_url": "https://api.office-integrator.com/writer/officeapi/v1/documents/d26aa7b8029bf4f8d34c7dd0013939234a6e15dac88646f02a69582375b8da130efffac249d0erouae4667dcbcfb7ac1d/edit",
"document_id": "1349",
"save_url": "https://api.office-integrator.com/writer/officeapi/v1/documents/d26aa7b8029bf4f8d34c7dd0013939234a6e15dac88646f02a69582375b8da130efffac249d086aae4667dcbcfb7ac1d/save",
"session_id": "axxrd26aa7b8029bf4f8d34c7dd0013939234a6e15dac88646f02a69582375b8da130efffac249d086aae4667dcbac9p",
"session_delete_url": "https://api.office-integrator.com/writer/officeapi/v1/sessions/d26aa7b8029bf4f8d34c7dd0013939234a6e15dac88646f02a69582375b8da130efffac249d086aae4667dcbcfb7ac1d",
"document_delete_url": "https://api.office-integrator.com/writer/officeapi/v1/documents/1349",
}