Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Accept or Reject Tracked Changes in Word using a REST API in Node.js
// Create an instance of the API
let reviewApi = groupdocs_comparison_cloud.ReviewApi.fromKeys(clientId, clientSecret);
// Input source file
let source = new groupdocs_comparison_cloud.FileInfo();
source.filePath = "source_with_revisions.docx";
// Define apply revision options
let options = new groupdocs_comparison_cloud.ApplyRevisionsOptions();
options.sourceFile = source;
options.outputPath = "output.docx";
// Accept all revisions
options.acceptAll = true;
// Reject all revisions
// options.rejectAll = true;
// Create apply revision request
let request = new groupdocs_comparison_cloud.ApplyRevisionsRequest(options);
// Apply revisions
let response = await reviewApi.applyRevisions(request);
console.log("Output file link: " + response.href);
// Create an instance of the API
let reviewApi = groupdocs_comparison_cloud.ReviewApi.fromKeys(clientId, clientSecret);
// Input source file
let source = new groupdocs_comparison_cloud.FileInfo();
source.filePath = "source_with_revisions.docx";
// Define apply revisions options
let options = new groupdocs_comparison_cloud.ApplyRevisionsOptions();
options.sourceFile = source;
options.outputPath = "output.docx";
// Create get revisions request
let request = new groupdocs_comparison_cloud.GetRevisionsRequest(source);
// Get all revisions
let revisions = await reviewApi.getRevisions(request);
// Accept or Reject revisions
revisions.forEach(revision => {
revision.action = groupdocs_comparison_cloud.RevisionInfo.ActionEnum.Accept;
});
options.revisions = revisions;
// Create apply revisions request
let applyRequest = new groupdocs_comparison_cloud.ApplyRevisionsRequest(options);
// Apply revisions
let response = await reviewApi.applyRevisions(applyRequest);
console.log("Output file link: " + response.href);
global.clientId = "112f0f38-9dae-42d5-b4fc-cc84ae644972";
global.clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618";
global.myStorage = "";
const config = new groupdocs_comparison_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";
// Construct FileApi
let fileApi = groupdocs_comparison_cloud.FileApi.fromConfig(config);
// Create download file request
let request = new groupdocs_comparison_cloud.DownloadFileRequest("output.docx", myStorage);
// Download file
let response = await fileApi.downloadFile(request);
// Save in the working directory
fs.writeFile("C:\\Files\\output.docx", response, "binary", function (err) { });
// Construct FileApi
let fileApi = groupdocs_comparison_cloud.FileApi.fromConfig(config);
// Input file path
let file = 'C:\\Files\\source_with_revisions.docx';
// Read file
fs.readFile(file, (err, fileStream) => {
// Create upload file request
let request = new groupdocs_comparison_cloud.UploadFileRequest("source_with_revisions.docx", fileStream, myStorage);
// Upload file
fileApi.uploadFile(request);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment