Accept or Reject Tracked Changes in Word using Node.js

Microsoft Word provides a built-in functionality to track changes and keep revisions in Word documents. However, we may accept or reject the tracked changes of Word documents (DOC or DOCX) programmatically on the cloud. In this article, we will learn how to accept or reject tracked changes in a Word document using a REST API in Node.js.

The following topics shall be covered in this article:

REST API and Node.js SDK to Accept or Reject Changes

For accepting or rejecting the tracked changes in a Word document, we will be using the Node.js SDK of GroupDocs.Comparison Cloud API. It allows comparing two or more documents of the supported formats and tracking their changes. Please install it using the following command in the console:

npm install groupdocs-comparison-cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Accept or Reject Tracked Changes using REST API in Node.js

We can accept or reject specific revisions in Word documents by following the simple steps given below:

  1. Upload the DOCX files to the Cloud
  2. Accept or Reject Changes in Word Documents
  3. Download the output file

Upload the Document

Firstly, we will upload the Word document with revisions to the cloud using the code example given below:

As a result, the uploaded DOCX file will be available in the files section of the dashboard on the cloud.

Accept or Reject Changes in Word Documents

Now, we will accept or reject tracked changes programmatically by following the steps given below:

  • Firstly, create an instance of the ReviewApi.
  • Next, provide the uploaded DOCX file path.
  • Then, get revisions and accept or reject the desired revisions in a loop.
  • Finally, apply revisions and save the updated file as “output.docx”.

The following code sample shows how to accept the tracked changes in a Word document using a REST API in Node.js.

Accept or Reject Tracked Changes using REST API in Node.js

Accept or Reject Tracked Changes using REST API in Node.js

Similarly, we can reject any changes by following the steps mentioned earlier. However, we just need to apply the following revision options:

revisions.forEach(revision => {
	revision.action = groupdocs_comparison_cloud.RevisionInfo.ActionEnum.Reject;
});

Download the Resultant File

As a result, the above code example will save a newly created DOCX file with changes on the cloud. It can be downloaded using the following code sample:

Accept or Reject All the Changes in Node.js

We can accept or reject all the changes at once by following the steps given below:

  • Firstly, create an instance of the ReviewApi.
  • Next, provide the uploaded DOCX file path.
  • Then, get revisions and accept or reject all the revisions.
  • Finally, apply revisions and save the updated file as “output.docx”.

The following code sample shows how to accept all the changes using a REST API. Please follow the steps mentioned earlier to upload and download the file.

Try Online

Please try the following free online DOCX comparison tool, which is developed using the above API. https://products.groupdocs.app/comparison/docx

Conclusion

In this article, we have learned how to accept or reject tracked changes in Word documents using a REST API on the cloud. We have also seen how to accept or reject all the revisions in one go programmatically. This article also explained how to programmatically upload a DOCX file to the cloud and then download the resultant file from the cloud. Besides, you can learn more about GroupDocs.Comparison Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.

See Also