Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Accept or Reject Tracked Changes of Word Document using a REST API on the cloud in Python.
Accept or Reject Tracked Changes using Python
1. Programmatically upload DOCX file on the cloud
2. Accept or Reject Tracked Changes programmatically using Python.
3. Download the output files from the cloud.
# Create an instance of the API
api_instance = groupdocs_comparison_cloud.ReviewApi.from_keys(client_id, client_secret)
# Set source file
source = groupdocs_comparison_cloud.FileInfo()
source.file_path = "source_with_revs.docx"
options = groupdocs_comparison_cloud.ApplyRevisionsOptions()
options.source_file = source
options.output_path = "output/result.docx"
request = groupdocs_comparison_cloud.GetRevisionsRequest(options)
revisions = api_instance.get_revisions(request)
# Get all revisions count
print("Revisions count: " + str(len(revisions)))
# Accept revisions
for revision in revisions:
revision.action = "Accept"
options.revisions = revisions
request = groupdocs_comparison_cloud.ApplyRevisionsRequest(options)
response = api_instance.apply_revisions(request)
# Create an instance of the API
api_instance = groupdocs_comparison_cloud.ReviewApi.from_keys(client_id, client_secret)
# Set source file
source = groupdocs_comparison_cloud.FileInfo()
source.file_path = "source_with_revs.docx"
options = groupdocs_comparison_cloud.ApplyRevisionsOptions()
options.source_file = source
options.output_path = "output/result.docx"
# Accept all revisions
options.accept_all = True
request = groupdocs_comparison_cloud.ApplyRevisionsRequest(options)
response = api_instance.apply_revisions(request)
client_id = "112f0f38-9dae-42d5-b4fc-cc84ae644972"
client_secret = "16ad3fe0bdc39c910f57d2fd48a5d618"
configuration = groupdocs_comparison_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
my_storage = ""
# API initialization
file_api = groupdocs_comparison_cloud.FileApi.from_config(configuration)
request = groupdocs_comparison_cloud.DownloadFileRequest("output\\result.docx", my_storage)
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\")
# Create an instance of the API
file_api = groupdocs_comparison_cloud.FileApi.from_config(configuration)
request = groupdocs_comparison_cloud.UploadFileRequest("source_with_revs.docx", "C:\\Files\\source_with_revs.docx", "")
response = file_api.upload_file(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment