Comparison API

Zoho Writer comparison API provides a user-friendly viewer for comparing documents.

The API accepts a pair of documents as input and returns a comparison viewer URL as a response. When a user accesses the said URL in a browser, the documents are displayed in Writer with changes highlighted.


To compare two versions of a document and highlight the difference in text.

HTTP Request URL


Request Parameters

ParameterData TypeDescription
Mandatory Parameters
apikey423s*****Uniquely identifies the web application, which initiates the document comparison request.




Method of providing the input file depending on its location.

document1 - if the 1st version of the input file is from your local drive or desktop.

url1 - if the 1st version of the input file is from a publicly accessible Web URL.




Method of providing the input file depending on its location.

document2 - if the 2nd version of the input file is from your local drive or desktop.

url2 - if the 2nd version of the input file is from a publicly accessible Web URL.
Optional Parameters
titleStringDefines document title of the 2 versions of comparison files. 
Note: If the user fails to provide value for 'title' parameter, Zoho Writer will combine the names from 'document1' & 'document2' parameters, and replace it as the title
langStringEnables the editor interface to open in Writer supported languages.
Default value: en (English)


Comparison API - Error Codes

1831Error occurred. Parameter value is either incorrect or invalid.
1852File format you're trying to import is not supported.
1868Invalid parameter name for uploaded content.

For a full list of error handling cases in Comparison API, refer here.

Sample Request

				curl --request POST \
  --url '' \
  --header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  --form document1=@/Users/username/Documents/Sample_V1.docx \
  --form document2=@/Users/username/Documents/Sample_V2.docx \
  --form 'apikey=423s*****'			

Sample Response


Sample Snippet

				const 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 fs = require("fs");
const StreamWrapper = require("zoi-nodejs-sdk/utils/util/stream_wrapper").StreamWrapper;
const CompareDocumentResponse = require("zoi-nodejs-sdk/core/com/zoho/officeintegrator/office_integrator_sdk/compare_document_response").CompareDocumentResponse;
const CompareDocumentParameters = require("zoi-nodejs-sdk/core/com/zoho/officeintegrator/office_integrator_sdk/compare_document_parameters").CompareDocumentParameters;
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 CompareDocument {

    //Include zoi-nodejs-sdk package in your package json and the execute this code.

    static async initializeSdk() {
        let user = new UserSignature("");
        let environment = new Environment("", null, null);
        let apikey = new APIKey("2ae438cf864488657cc9754a27daa480", Constants.PARAMS);
        let logger = new LogBuilder()
        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 compareDocumentParameters = new CompareDocumentParameters();


            var file1Name = "MS_Word_Document_v0.docx";
            // var file1Path = __dirname + "/sample_documents/MS_Word_Document_v0.docx";
            // var file1Stream = fs.readFileSync(file1Path);
            // var stream1Wrapper = new StreamWrapper(file1Name, file1Stream, file1Path)
            // var stream1Wrapper = new StreamWrapper(null, null, file1Path)

            var file2Name = "MS_Word_Document_v1.docx";
            // var file2Path = __dirname + "/sample_documents/MS_Word_Document_v1.docx";
            // var file2Stream = fs.readFileSync(file2Path);
            // var stream2Wrapper = new StreamWrapper(file2Name, file2Stream, file2Path)
            // var stream2Wrapper = new StreamWrapper(null, null, file2Path)
            // compareDocumentParameters.setDocument1(stream1Wrapper);
            // compareDocumentParameters.setDocument2(stream2Wrapper);

            compareDocumentParameters.setTitle(file1Name + " vs " + file2Name);

            var responseObject = await sdkOperations.compareDocument(compareDocumentParameters);

            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 CompareDocumentResponse instance is received
                    if(writerResponseObject instanceof CompareDocumentResponse) {
                        console.log("\nCompare URL - " + writerResponseObject.getCompareUrl());
                        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);