├── requirements.txt ├── save-callback-implementation └── Flask │ ├── requirements.txt │ ├── README.md │ └── save_callback.py ├── pdf-apis ├── sample_documents │ ├── document1.pdf │ ├── document2.pdf │ └── BusinessIntelligence.pdf ├── run.py ├── DeletePdfDocument.py ├── DeletePdfDocumentSession.py ├── GetPdfSessionDetails.py ├── GetPdfDocumentDetails.py └── EditPdf.py ├── document-apis ├── sample_documents │ ├── document1.pdf │ ├── document2.pdf │ ├── OfferLetter.zdoc │ ├── watermark_output.docx │ ├── MS_Word_Document_v0.docx │ ├── MS_Word_Document_v1.docx │ ├── Graphic-Design-Proposal.docx │ └── candidates.json ├── run.py ├── GetMergeFields.py ├── CompareDocument.py ├── PreviewDocument.py ├── DeleteDocument.py ├── DeleteDocumentSession.py ├── CombinePdf.py ├── WatermarkDocument.py ├── ConvertDocument.py ├── MergeAndDownload.py ├── GetDocumentDetails.py ├── MergeAndDeliver.py ├── GetSessionDetails.py ├── GetAllSessions.py ├── CreateDocument.py ├── EditDocument.py └── CreateMergeTemplate.py ├── presentation-apis ├── sample_documents │ └── Zoho_Show.pptx ├── run.py ├── PreviewPresentation.py ├── ConvertPresentation.py ├── DeletePresentation.py ├── DeletePresentationSession.py ├── GetSessionDetails.py ├── CreatePresentation.py └── EditPresentation.py ├── spreadsheet-apis ├── sample_documents │ └── Contact_List.xlsx ├── run.py ├── PreviewSpreadsheet.py ├── DeleteSpreadsheet.py ├── DeleteSpreadsheetSession.py ├── ConvertSpreadsheet.py ├── GetSessionDetails.py ├── CreateSpreadsheet.py └── EditSpreadsheet.py ├── LICENSE ├── InitializeSdk.py ├── README.md ├── GetPlanDetails.py └── .gitignore /requirements.txt: -------------------------------------------------------------------------------- 1 | office-integrator-sdk==1.0.2 2 | -------------------------------------------------------------------------------- /save-callback-implementation/Flask/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.3.3 -------------------------------------------------------------------------------- /pdf-apis/sample_documents/document1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/pdf-apis/sample_documents/document1.pdf -------------------------------------------------------------------------------- /pdf-apis/sample_documents/document2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/pdf-apis/sample_documents/document2.pdf -------------------------------------------------------------------------------- /document-apis/sample_documents/document1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/document-apis/sample_documents/document1.pdf -------------------------------------------------------------------------------- /document-apis/sample_documents/document2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/document-apis/sample_documents/document2.pdf -------------------------------------------------------------------------------- /document-apis/sample_documents/OfferLetter.zdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/document-apis/sample_documents/OfferLetter.zdoc -------------------------------------------------------------------------------- /pdf-apis/sample_documents/BusinessIntelligence.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/pdf-apis/sample_documents/BusinessIntelligence.pdf -------------------------------------------------------------------------------- /presentation-apis/sample_documents/Zoho_Show.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/presentation-apis/sample_documents/Zoho_Show.pptx -------------------------------------------------------------------------------- /document-apis/sample_documents/watermark_output.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/document-apis/sample_documents/watermark_output.docx -------------------------------------------------------------------------------- /spreadsheet-apis/sample_documents/Contact_List.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/spreadsheet-apis/sample_documents/Contact_List.xlsx -------------------------------------------------------------------------------- /document-apis/sample_documents/MS_Word_Document_v0.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/document-apis/sample_documents/MS_Word_Document_v0.docx -------------------------------------------------------------------------------- /document-apis/sample_documents/MS_Word_Document_v1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/document-apis/sample_documents/MS_Word_Document_v1.docx -------------------------------------------------------------------------------- /document-apis/sample_documents/Graphic-Design-Proposal.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zoho/office-integrator-python-sdk-examples/main/document-apis/sample_documents/Graphic-Design-Proposal.docx -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2024, ZOHO CORPORATION PRIVATE LIMITED 2 | All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | -------------------------------------------------------------------------------- /pdf-apis/run.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import sys 4 | 5 | 6 | def run_all_python_files_in_folder(folder_path): 7 | # List all files in the given folder 8 | files = os.listdir(folder_path) 9 | 10 | # Filter out files that have a .py extension and are not run.py 11 | python_files = [f for f in files if f.endswith('.py') and f != 'run.py'] 12 | 13 | # Run each Python file 14 | for python_file in python_files: 15 | file_path = os.path.join(folder_path, python_file) 16 | try: 17 | result = subprocess.run(['python3', file_path], check=True, capture_output=True, text=True) 18 | print(f'Output of {python_file}:\n{result.stdout}') 19 | except subprocess.CalledProcessError as e: 20 | print(f'Error running {python_file}:\n{e.stderr}') 21 | 22 | 23 | if __name__ == "__main__": 24 | if len(sys.argv) == 2: 25 | folder_path = sys.argv[1] 26 | else: 27 | folder_path = os.getcwd() # Use current directory as default 28 | 29 | run_all_python_files_in_folder(folder_path) 30 | -------------------------------------------------------------------------------- /document-apis/run.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import sys 4 | 5 | 6 | def run_all_python_files_in_folder(folder_path): 7 | # List all files in the given folder 8 | files = os.listdir(folder_path) 9 | 10 | # Filter out files that have a .py extension and are not run.py 11 | python_files = [f for f in files if f.endswith('.py') and f != 'run.py'] 12 | 13 | # Run each Python file 14 | for python_file in python_files: 15 | file_path = os.path.join(folder_path, python_file) 16 | try: 17 | result = subprocess.run(['python3', file_path], check=True, capture_output=True, text=True) 18 | print(f'Output of {python_file}:\n{result.stdout}') 19 | except subprocess.CalledProcessError as e: 20 | print(f'Error running {python_file}:\n{e.stderr}') 21 | 22 | 23 | if __name__ == "__main__": 24 | if len(sys.argv) == 2: 25 | folder_path = sys.argv[1] 26 | else: 27 | folder_path = os.getcwd() # Use current directory as default 28 | 29 | run_all_python_files_in_folder(folder_path) 30 | -------------------------------------------------------------------------------- /presentation-apis/run.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import sys 4 | 5 | 6 | def run_all_python_files_in_folder(folder_path): 7 | # List all files in the given folder 8 | files = os.listdir(folder_path) 9 | 10 | # Filter out files that have a .py extension and are not run.py 11 | python_files = [f for f in files if f.endswith('.py') and f != 'run.py'] 12 | 13 | # Run each Python file 14 | for python_file in python_files: 15 | file_path = os.path.join(folder_path, python_file) 16 | try: 17 | result = subprocess.run(['python3', file_path], check=True, capture_output=True, text=True) 18 | print(f'Output of {python_file}:\n{result.stdout}') 19 | except subprocess.CalledProcessError as e: 20 | print(f'Error running {python_file}:\n{e.stderr}') 21 | 22 | 23 | if __name__ == "__main__": 24 | if len(sys.argv) == 2: 25 | folder_path = sys.argv[1] 26 | else: 27 | folder_path = os.getcwd() # Use current directory as default 28 | 29 | run_all_python_files_in_folder(folder_path) 30 | -------------------------------------------------------------------------------- /spreadsheet-apis/run.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import sys 4 | 5 | 6 | def run_all_python_files_in_folder(folder_path): 7 | # List all files in the given folder 8 | files = os.listdir(folder_path) 9 | 10 | # Filter out files that have a .py extension and are not run.py 11 | python_files = [f for f in files if f.endswith('.py') and f != 'run.py'] 12 | 13 | # Run each Python file 14 | for python_file in python_files: 15 | file_path = os.path.join(folder_path, python_file) 16 | try: 17 | result = subprocess.run(['python3', file_path], check=True, capture_output=True, text=True) 18 | print(f'Output of {python_file}:\n{result.stdout}') 19 | except subprocess.CalledProcessError as e: 20 | print(f'Error running {python_file}:\n{e.stderr}') 21 | 22 | 23 | if __name__ == "__main__": 24 | if len(sys.argv) == 2: 25 | folder_path = sys.argv[1] 26 | else: 27 | folder_path = os.getcwd() # Use current directory as default 28 | 29 | run_all_python_files_in_folder(folder_path) 30 | -------------------------------------------------------------------------------- /InitializeSdk.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | 7 | 8 | class InitializeSdk(object): 9 | 10 | @staticmethod 11 | def execute(self): 12 | try: 13 | #Sdk application log configuration 14 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 15 | #Update this apikey with your own apikey signed up in office integrator service 16 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 17 | tokens = [ auth ] 18 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 19 | environment = DataCenter.Production("https://api.office-integrator.com") 20 | 21 | Initializer.initialize(environment, tokens,None, None, logger, None) 22 | 23 | except SDKException as ex: 24 | print(ex.code) 25 | -------------------------------------------------------------------------------- /document-apis/sample_documents/candidates.json: -------------------------------------------------------------------------------- 1 | { 2 | "fields":[ 3 | 4 | {"id":"FirstName","display_name":"First Name","type":"String"}, 5 | {"id":"LastName","display_name":"Last Name","type":"String"}, 6 | {"id":"Company","display_name":"Company","type":"String"}, 7 | {"id":"Salary","display_name":"Salary","type":"String"}, 8 | {"id":"jobTitle","display_name":"jobTitle","type":"String"}, 9 | {"id":"Location","display_name":"Location","type":"String"}, 10 | {"id":"Address Line 1","display_name":"Address Line 1","type":"String"}, 11 | {"id":"Address Line 2","display_name":"Address Line 2","type":"String"}, 12 | {"id":"zipCode","display_name":"zipCode","type":"String"} 13 | ], 14 | "data":[ 15 | { 16 | "FirstName":"Romin","LastName":"Irani","Company":"Zylker Corp","Salary":"20000","Location":"Pleasonton","Address Line 1":"4665 Bernal Ave.","Address Line 2":"Pleasanton, CA","zipCode":"CA 408-1234567"}, 17 | { 18 | "FirstName":"Neil","LastName":"Stephen","Company":"Zylker Corp","Salary":"10000","Location":"Pleasonton","Address Line 1":"4665 Bernal Ave.","Address Line 2":"New York","zipCode":"NY 94566-7498"}, 19 | { 20 | "FirstName":"Tom","LastName":"Hanks","Company":"Zylker Corp","Salary":"50000","Location":"Pleasonton","Address Line 1":"4665 Bernal Ave.","Address Line 2":"Washington","zipCode":"WT 94566-7498"} 21 | ] 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zoho Office Integrator - Python SDK Example Codes 2 | 3 | 4 | ## Getting Started 5 | 6 | Zoho Office Integrator Python SDK used to help you quickly integrator Zoho Office Integrator editors in side your web application. This repository will example code to integrate Zoho Office Integrator using Python SDK. 7 | 8 | ## How to run the example codes 9 | 10 | - Clone this repository in your local machine. 11 | ```sh 12 | git clone https://github.com/zoho/office-integrator-python-sdk-examples.git 13 | ``` 14 | 15 | - Install [**Python SDK**](https://pypi.org/project/office-integrator-sdk) and other dependencies 16 | - Navigate to the folder **office-integrator-python-sdk-examples** 17 | ```sh 18 | cd office-integrator-python-sdk-examples 19 | ``` 20 | 21 | - Run the command below. This command will install python sdk and it's dependencies. 22 | ```sh 23 | pip3 install -r requirements.txt 24 | ``` 25 | 26 | - Now go to any of the folder document-apis 27 | ```sh 28 | cd document-apis 29 | ``` 30 | 31 | - Run any of the example files in those folders. 32 | ```sh 33 | python3 CreateDocument.py 34 | ``` 35 | - You can make the changes in any of the example code and test if your changes get reflected in the output. 36 | 37 | - Check the [documentation page](https://www.zoho.com/officeplatform/integrator/api/v1/) for all possible customizations. 38 | 39 | ## License 40 | 41 | This SDK is distributed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0), see LICENSE.txt for more information. 42 | -------------------------------------------------------------------------------- /save-callback-implementation/Flask/README.md: -------------------------------------------------------------------------------- 1 | Save the [code](https://raw.githubusercontent.com/iampraba/zoi-python-sdk-examples/main/save-callback-implementation/Flask/save_callback.py) in a file, for example, save_callback.py. 2 | 3 | To run the following commands from your Mac terminal, you should have python and pip command installed on you machine. 4 | 5 | Open the terminal, navigate to the directory save-callback-implementation, and run the following command: 6 | 7 | - Run the command below. This command will install python sdk and it's dependencies. 8 | ```sh 9 | pip3 install -r requirements.txt 10 | ``` 11 | 12 | - Run any of the example files in those folders. 13 | ```sh 14 | python3 save_callback.py 15 | ``` 16 | 17 | This will start the api end point to receive file. You can access the API endpoint at http://localhost:5000/zoho/file/uploader. 18 | 19 | Test above api end point and verify if the file store without any error. You could free to edit the code to fit your application needs. 20 | 21 | To host this code on a server so that it can be accessed from the internet, you would need a web server with nodejs support. Here are the general steps: 22 | 23 | - Choose a hosting provider or set up your own server with a web server software like Apache or Nginx. 24 | - Upload the your save_callback.py file to your server. 25 | - Make sure the server has python installed and properly configured. 26 | - Ensure that the destination folder for uploaded files has appropriate write permissions. 27 | - Access the API endpoint using the server's domain or IP address, e.g., http://zylker.com//zoho/file/uploader. 28 | 29 | Note that the exact steps may vary depending on your hosting environment and configuration. It's recommended to refer to the documentation provided by your hosting provider or the server software you choose for more detailed instructions. 30 | -------------------------------------------------------------------------------- /save-callback-implementation/Flask/save_callback.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, jsonify 2 | import os 3 | 4 | app = Flask(__name__) 5 | 6 | # Define a route to handle POST requests with multipart form data 7 | @app.route('/zoho/file/uploader', methods=['POST']) 8 | def handle_upload(): 9 | try: 10 | # Check if the 'file' field is in the request 11 | if 'file' not in request.files: 12 | return jsonify({"error": "No file part"}), 400 13 | 14 | file = request.files['file'] 15 | 16 | # Check if the file is empty 17 | if file.filename == '': 18 | return jsonify({"error": "No selected file"}), 400 19 | else: 20 | print("File read from request = " + file.filename) 21 | 22 | # Save the uploaded file to a designated directory 23 | root_dir = os.path.dirname(os.path.abspath(__file__)) 24 | 25 | dest_file_path = os.path.join(root_dir, file.filename) 26 | 27 | file.save(dest_file_path) 28 | 29 | print("File saved in file path = " + dest_file_path) 30 | 31 | # You can also access other form fields if needed. 32 | # For example assume filename and format key sent along with 33 | file_name = request.form.get('filename') 34 | format = request.form.get('format') 35 | 36 | print("file_name read from request body = " + str(file_name)) 37 | print("format from from request body = " + str(format)) 38 | 39 | # Process the uploaded file and form data as needed 40 | 41 | # Send a response back to Zoho API to acknowledge the callback successfully completed. 42 | # String value given for message key below will shown as save status in editor UI. 43 | response_data = {"message": "File uploaded successfully"} 44 | 45 | return jsonify(response_data), 200 46 | except Exception as e: 47 | return jsonify({"error": str(e)}), 400 48 | 49 | print('\nMake a post request to this end point to test save callback from local file - http://localhost/${port}${callbackEndpoint}') 50 | print('\nKeep the multipart key as content for file. If you send the file in different key then change the key in save_callback code as well before testing') 51 | print('\nYou should not use http://localhost/${port} as save_url in callback settings. You should only use it as publicly accessible(with your application domain) end point.') 52 | 53 | if __name__ == '__main__': 54 | app.run(debug=True) 55 | -------------------------------------------------------------------------------- /GetPlanDetails.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, PlanDetails, Authentication 7 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 8 | 9 | 10 | class GetPlanDetails: 11 | 12 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/get-plan-details.html 13 | @staticmethod 14 | def execute(): 15 | GetPlanDetails.init_sdk() 16 | 17 | v1Operations = V1Operations() 18 | response = v1Operations.get_plan_details() 19 | 20 | if response is not None: 21 | print('Status Code: ' + str(response.get_status_code())) 22 | responseObject = response.get_object() 23 | 24 | if responseObject is not None: 25 | if isinstance(responseObject, PlanDetails): 26 | print("\nPlan name - " + str(responseObject.get_plan_name())) 27 | print("API usage limit - " + str(responseObject.get_usage_limit())) 28 | print("API usage so far - " + str(responseObject.get_total_usage())) 29 | print("Plan upgrade payment link - " + str(responseObject.get_payment_link())) 30 | print("Subscription period - " + str(responseObject.get_subscription_period())) 31 | print("Subscription interval - " + str(responseObject.get_subscription_interval())) 32 | elif isinstance(responseObject, InvalidConfigurationException): 33 | print('Invalid configuration exception.') 34 | print('Error Code : ' + str(responseObject.get_code())) 35 | print("Error Message : " + str(responseObject.get_message())) 36 | if responseObject.get_parameter_name() is not None: 37 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 38 | if responseObject.get_key_name() is not None: 39 | print("Error Key Name : " + str(responseObject.get_key_name())) 40 | else: 41 | print('Get Plan Details Request Failed') 42 | 43 | @staticmethod 44 | def init_sdk(): 45 | try: 46 | #Sdk application log configuration 47 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 48 | #Update this apikey with your own apikey signed up in office integrator service 49 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 50 | tokens = [ auth ] 51 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 52 | environment = DataCenter.Production("https://api.office-integrator.com") 53 | 54 | Initializer.initialize(environment, tokens,None, None, logger, None) 55 | except SDKException as ex: 56 | print(ex.code) 57 | 58 | 59 | GetPlanDetails.execute() 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | myenv/ 128 | ENV/ 129 | env.bak/ 130 | venv.bak/ 131 | 132 | # Spyder project settings 133 | .spyderproject 134 | .spyproject 135 | 136 | # Rope project settings 137 | .ropeproject 138 | 139 | # mkdocs documentation 140 | /site 141 | 142 | # mypy 143 | .mypy_cache/ 144 | .dmypy.json 145 | dmypy.json 146 | 147 | # Pyre type checker 148 | .pyre/ 149 | 150 | # pytype static type analyzer 151 | .pytype/ 152 | 153 | # Cython debug symbols 154 | cython_debug/ 155 | 156 | # PyCharm 157 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 158 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 159 | # and can be added to the global gitignore or merged into this file. For a more nuclear 160 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 161 | .idea/ 162 | logs.txt 163 | .DS_Store -------------------------------------------------------------------------------- /document-apis/GetMergeFields.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 7 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 8 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 9 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 10 | GetMergeFieldsParameters, MergeFieldsResponse, MergeFields, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | class GetMergeFields: 14 | 15 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/get-list-of-fields-in-the-document.html 16 | @staticmethod 17 | def execute(): 18 | GetMergeFields.init_sdk() 19 | getMergeFilesParams = GetMergeFieldsParameters() 20 | 21 | # Either use url as document source or attach the document in request body use below methods 22 | getMergeFilesParams.set_file_url("https://demo.office-integrator.com/zdocs/OfferLetter.zdoc") 23 | 24 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 25 | # filePath = ROOT_DIR + "/sample_documents/OfferLetter.zdoc" 26 | # print('Path for source file to be edited : ' + filePath) 27 | # getMergeFilesParams.set_file_content(StreamWrapper(file_path=filePath)) 28 | 29 | v1Operations = V1Operations() 30 | response = v1Operations.get_merge_fields(getMergeFilesParams) 31 | 32 | if response is not None: 33 | print('Status Code: ' + str(response.get_status_code())) 34 | responseObject = response.get_object() 35 | 36 | if responseObject is not None: 37 | if isinstance(responseObject, MergeFieldsResponse): 38 | mergeFieldsObj = responseObject.get_merge() 39 | 40 | if isinstance(mergeFieldsObj, list): 41 | print('\n---- Total Fields in Document : ' + str(len(mergeFieldsObj)) + " ----") 42 | for mergeFieldObj in mergeFieldsObj: 43 | if isinstance(mergeFieldObj, MergeFields): 44 | print('\nMerge Field ID : ' + mergeFieldObj.get_id()) 45 | print('Merge Field Display Name : ' + mergeFieldObj.get_display_name()) 46 | print('Merge Field Type : ' + mergeFieldObj.get_type()) 47 | 48 | elif isinstance(responseObject, InvalidConfigurationException): 49 | print('Invalid configuration exception.') 50 | print('Error Code : ' + str(responseObject.get_code())) 51 | print("Error Message : " + str(responseObject.get_message())) 52 | if responseObject.get_parameter_name() is not None: 53 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 54 | if responseObject.get_key_name() is not None: 55 | print("Error Key Name : " + str(responseObject.get_key_name())) 56 | else: 57 | print('Create Merge Fields Request Failed') 58 | 59 | @staticmethod 60 | def init_sdk(): 61 | try: 62 | #Sdk application log configuration 63 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 64 | #Update this apikey with your own apikey signed up in office integrator service 65 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 66 | tokens = [ auth ] 67 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 68 | environment = DataCenter.Production("https://api.office-integrator.com") 69 | 70 | Initializer.initialize(environment, tokens,None, None, logger, None) 71 | except SDKException as ex: 72 | print(ex.code) 73 | 74 | GetMergeFields.execute() -------------------------------------------------------------------------------- /document-apis/CompareDocument.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | 9 | from officeintegrator.src.com.zoho.officeintegrator.v1 import CompareDocumentParameters, CompareDocumentResponse, \ 10 | InvalidConfigurationException, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 13 | 14 | class CompareDocument: 15 | 16 | # Refer Compare API documentation - https://www.zoho.com/officeintegrator/api/v1/writer-comparison-api.html 17 | @staticmethod 18 | def execute(): 19 | CompareDocument.init_sdk() 20 | compareDocumentParameters = CompareDocumentParameters(); 21 | 22 | # Either use url as document source or attach the document in request body use below methods 23 | compareDocumentParameters.set_url1('https://demo.office-integrator.com/zdocs/MS_Word_Document_v0.docx') 24 | compareDocumentParameters.set_url2('https://demo.office-integrator.com/zdocs/MS_Word_Document_v1.docx') 25 | 26 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 27 | 28 | file1Name = "MS_Word_Document_v0.docx" 29 | # file1Path = ROOT_DIR + "/sample_documents/" + file1Name 30 | # print('source file1 path : ' + file1Path) 31 | # compareDocumentParameters.set_document1(StreamWrapper(file_path=file1Path)) 32 | 33 | file2Name = "MS_Word_Document_v1.docx" 34 | # file2Path = ROOT_DIR + "/sample_documents/" + file2Name 35 | # print('source file1 path : ' + file2Path) 36 | # compareDocumentParameters.set_document2(StreamWrapper(file_path=file2Path)) 37 | 38 | compareDocumentParameters.set_lang("en") 39 | compareDocumentParameters.set_title(file1Name + " vs " + file2Name) 40 | 41 | v1Operations = V1Operations() 42 | response = v1Operations.compare_document(compareDocumentParameters) 43 | 44 | if response is not None: 45 | print('Status Code: ' + str(response.get_status_code())) 46 | responseObject = response.get_object() 47 | 48 | if responseObject is not None: 49 | if isinstance(responseObject, CompareDocumentResponse): 50 | print('Document Compare Session URL : ' + str(responseObject.get_compare_url())) 51 | print('Document Compare Session Delete URL : ' + str(responseObject.get_session_delete_url())) 52 | elif isinstance(responseObject, InvalidConfigurationException): 53 | print('Invalid configuration exception.') 54 | print('Error Code : ' + str(responseObject.get_code())) 55 | print("Error Message : " + str(responseObject.get_message())) 56 | if responseObject.get_parameter_name() is not None: 57 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 58 | if responseObject.get_key_name() is not None: 59 | print("Error Key Name : " + str(responseObject.get_key_name())) 60 | else: 61 | print('Compare Document Request Failed') 62 | 63 | @staticmethod 64 | def init_sdk(): 65 | try: 66 | #Sdk application log configuration 67 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 68 | #Update this apikey with your own apikey signed up in office integrator service 69 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 70 | tokens = [ auth ] 71 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 72 | environment = DataCenter.Production("https://api.office-integrator.com") 73 | 74 | Initializer.initialize(environment, tokens,None, None, logger, None) 75 | except SDKException as ex: 76 | print(ex.code) 77 | 78 | 79 | CompareDocument.execute() 80 | -------------------------------------------------------------------------------- /spreadsheet-apis/PreviewSpreadsheet.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 9 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 10 | SheetPreviewParameters, SheetPreviewResponse, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | class PreviewSpreadsheet: 14 | 15 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-preview-spreadsheet.html 16 | @staticmethod 17 | def execute(): 18 | PreviewSpreadsheet.init_sdk() 19 | previewParameter = SheetPreviewParameters() 20 | 21 | # Either use url as document source or attach the document in request body use below methods 22 | previewParameter.set_url('https://demo.office-integrator.com/samples/sheet/Contact_List.xlsx') 23 | 24 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 25 | # filePath = ROOT_DIR + "/sample_documents/Contact_List.xlsx" 26 | # print('Path for source file to be edited : ' + filePath) 27 | # previewParameter.set_document(StreamWrapper(file_path=filePath)) 28 | 29 | # Optional Configuration - Configure permission values for session 30 | # based of you application requirement 31 | permissions = {} 32 | 33 | permissions["document.print"] = True 34 | permissions["document.export"] = True 35 | 36 | previewParameter.set_permissions(permissions) 37 | 38 | previewParameter.set_language('en') 39 | 40 | v1Operations = V1Operations() 41 | response = v1Operations.create_sheet_preview(previewParameter) 42 | 43 | if response is not None: 44 | print('Status Code: ' + str(response.get_status_code())) 45 | responseObject = response.get_object() 46 | 47 | if responseObject is not None: 48 | if isinstance(responseObject, SheetPreviewResponse): 49 | print('Spreadsheet Id : ' + str(responseObject.get_document_id())) 50 | print('Spreadsheet Session ID : ' + str(responseObject.get_session_id())) 51 | print('Spreadsheet Preview URL : ' + str(responseObject.get_preview_url())) 52 | print('Spreadsheet Session Delete URL : ' + str(responseObject.get_session_delete_url())) 53 | print('Spreadsheet Delete URL : ' + str(responseObject.get_document_delete_url())) 54 | elif isinstance(responseObject, InvalidConfigurationException): 55 | print('Invalid configuration exception.') 56 | print('Error Code : ' + str(responseObject.get_code())) 57 | print("Error Message : " + str(responseObject.get_message())) 58 | if responseObject.get_parameter_name() is not None: 59 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 60 | if responseObject.get_key_name() is not None: 61 | print("Error Key Name : " + str(responseObject.get_key_name())) 62 | else: 63 | print('Preview Spreadsheet Request Failed') 64 | 65 | @staticmethod 66 | def init_sdk(): 67 | try: 68 | #Sdk application log configuration 69 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 70 | #Update this apikey with your own apikey signed up in office integrator service 71 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 72 | tokens = [ auth ] 73 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 74 | environment = DataCenter.Production("https://api.office-integrator.com") 75 | 76 | Initializer.initialize(environment, tokens,None, None, logger, None) 77 | except SDKException as ex: 78 | print(ex.code) 79 | 80 | PreviewSpreadsheet.execute() -------------------------------------------------------------------------------- /presentation-apis/PreviewPresentation.py: -------------------------------------------------------------------------------- 1 | import time 2 | import os 3 | 4 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 5 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 6 | from officeintegrator.src.com.zoho.api.authenticator import Auth 7 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 8 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 9 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 10 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentInfo, InvalidConfigurationException, \ 11 | PreviewResponse, \ 12 | PresentationPreviewParameters, Authentication 13 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 14 | 15 | class PreviewPresentation: 16 | 17 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-show-preview-presentation.html 18 | @staticmethod 19 | def execute(): 20 | PreviewPresentation.init_sdk() 21 | previewParameter = PresentationPreviewParameters() 22 | 23 | # Either use url as document source or attach the document in request body use below methods 24 | previewParameter.set_url('https://demo.office-integrator.com/samples/show/Zoho_Show.pptx') 25 | 26 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 27 | # filePath = ROOT_DIR + "/sample_documents/Zoho_Show.pptx" 28 | # print('Path for source file to be edited : ' + filePath) 29 | # previewParameter.set_document(StreamWrapper(file_path=filePath)) 30 | 31 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 32 | documentInfo = DocumentInfo() 33 | documentInfo.set_document_name("New Document") 34 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 35 | 36 | previewParameter.set_document_info(documentInfo) 37 | 38 | previewParameter.set_language('en') 39 | 40 | v1Operations = V1Operations() 41 | response = v1Operations.create_presentation_preview(previewParameter) 42 | 43 | if response is not None: 44 | print('Status Code: ' + str(response.get_status_code())) 45 | responseObject = response.get_object() 46 | 47 | if responseObject is not None: 48 | if isinstance(responseObject, PreviewResponse): 49 | print('\nPresentation Id : ' + str(responseObject.get_document_id())) 50 | print('Presentation Session ID : ' + str(responseObject.get_session_id())) 51 | print('Presentation Preview URL : ' + str(responseObject.get_preview_url())) 52 | print('Presentation Session Delete URL : ' + str(responseObject.get_session_delete_url())) 53 | print('Presentation Delete URL : ' + str(responseObject.get_document_delete_url())) 54 | elif isinstance(responseObject, InvalidConfigurationException): 55 | print('Invalid configuration exception.') 56 | print('Error Code : ' + str(responseObject.get_code())) 57 | print("Error Message : " + str(responseObject.get_message())) 58 | if responseObject.get_parameter_name() is not None: 59 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 60 | if responseObject.get_key_name() is not None: 61 | print("Error Key Name : " + str(responseObject.get_key_name())) 62 | else: 63 | print('Preview Presentation Request Failed') 64 | 65 | @staticmethod 66 | def init_sdk(): 67 | try: 68 | #Sdk application log configuration 69 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 70 | #Update this apikey with your own apikey signed up in office integrator service 71 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 72 | tokens = [ auth ] 73 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 74 | environment = DataCenter.Production("https://api.office-integrator.com") 75 | 76 | Initializer.initialize(environment, tokens,None, None, logger, None) 77 | except SDKException as ex: 78 | print(ex.code) 79 | 80 | PreviewPresentation.execute() -------------------------------------------------------------------------------- /document-apis/PreviewDocument.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 9 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, PreviewParameters, \ 10 | PreviewDocumentInfo, PreviewResponse, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | class PreviewDocument: 14 | 15 | # Refer Preview API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-preview-document.html 16 | @staticmethod 17 | def execute(): 18 | PreviewDocument.init_sdk() 19 | previewParameter = PreviewParameters() 20 | 21 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 22 | documentInfo = PreviewDocumentInfo() 23 | documentInfo.set_document_name("New Document") 24 | 25 | previewParameter.set_document_info(documentInfo) 26 | 27 | # Optional Configuration - Configure permission values for session 28 | # based of you application requirement 29 | permissions = {} 30 | 31 | permissions["document.print"] = True 32 | 33 | previewParameter.set_permissions(permissions) 34 | 35 | # Either use url as document source or attach the document in request body use below methods 36 | previewParameter.set_url('https://demo.office-integrator.com/zdocs/LabReport.zdoc') 37 | 38 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 39 | # filePath = ROOT_DIR + "/sample_documents/Graphic-Design-Proposal.docx" 40 | # print('Path for source file to be edited : ' + filePath) 41 | # previewParameter.set_document(StreamWrapper(file_path=filePath)) 42 | 43 | v1Operations = V1Operations() 44 | response = v1Operations.create_document_preview(previewParameter) 45 | 46 | if response is not None: 47 | print('Status Code: ' + str(response.get_status_code())) 48 | responseObject = response.get_object() 49 | 50 | if responseObject is not None: 51 | if isinstance(responseObject, PreviewResponse): 52 | print('Document Id : ' + str(responseObject.get_document_id())) 53 | print('Document Session ID : ' + str(responseObject.get_session_id())) 54 | print('Document Preview URL : ' + str(responseObject.get_preview_url())) 55 | print('Document Session Delete URL : ' + str(responseObject.get_session_delete_url())) 56 | print('Document Delete URL : ' + str(responseObject.get_document_delete_url())) 57 | elif isinstance(responseObject, InvalidConfigurationException): 58 | print('Invalid configuration exception.') 59 | print('Error Code : ' + str(responseObject.get_code())) 60 | print("Error Message : " + str(responseObject.get_message())) 61 | if responseObject.get_parameter_name() is not None: 62 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 63 | if responseObject.get_key_name() is not None: 64 | print("Error Key Name : " + str(responseObject.get_key_name())) 65 | else: 66 | print('Preview Document Request Failed') 67 | 68 | @staticmethod 69 | def init_sdk(): 70 | try: 71 | #Sdk application log configuration 72 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 73 | #Update this apikey with your own apikey signed up in office integrator service 74 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 75 | tokens = [ auth ] 76 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 77 | environment = DataCenter.Production("https://api.office-integrator.com") 78 | 79 | Initializer.initialize(environment, tokens,None, None, logger, None) 80 | except SDKException as ex: 81 | print(ex.code) 82 | 83 | PreviewDocument.execute() -------------------------------------------------------------------------------- /spreadsheet-apis/DeleteSpreadsheet.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 7 | CreateSheetParameters, CreateSheetResponse, FileDeleteSuccessResponse, Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 9 | 10 | class DeleteSpreadsheet: 11 | 12 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-delete-spreadsheet.html 13 | @staticmethod 14 | def execute(): 15 | DeleteSpreadsheet.init_sdk() 16 | createSpreadsheetParams = CreateSheetParameters() 17 | 18 | print('Creating a spreadsheet to demonstrate spreadsheet delete api') 19 | v1Operations = V1Operations() 20 | response = v1Operations.create_sheet(createSpreadsheetParams) 21 | 22 | if response is not None: 23 | print('Status Code: ' + str(response.get_status_code())) 24 | responseObject = response.get_object() 25 | 26 | if responseObject is not None: 27 | if isinstance(responseObject, CreateSheetResponse): 28 | documentId = str(responseObject.get_document_id()) 29 | print('Spreadsheet ID to be deleted : ' + documentId) 30 | 31 | deleteApiResponse = v1Operations.delete_sheet(documentId) 32 | 33 | if deleteApiResponse is not None: 34 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 35 | deleteResponseObject = deleteApiResponse.get_object() 36 | 37 | if deleteResponseObject is not None: 38 | if isinstance(deleteResponseObject, FileDeleteSuccessResponse): 39 | print('Spreadsheet delete status : ' + str(deleteResponseObject.get_doc_delete())) 40 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 41 | print('Invalid configuration exception.') 42 | print('Error Code : ' + str(deleteResponseObject.get_code())) 43 | print("Error Message : " + str(deleteResponseObject.get_message())) 44 | if deleteResponseObject.get_parameter_name() is not None: 45 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 46 | if deleteResponseObject.get_key_name() is not None: 47 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 48 | else: 49 | print('Delete Spreadsheet Request Failed') 50 | elif isinstance(responseObject, InvalidConfigurationException): 51 | print('Invalid configuration exception.') 52 | print('Error Code : ' + str(responseObject.get_code())) 53 | print("Error Message : " + str(responseObject.get_message())) 54 | if responseObject.get_parameter_name() is not None: 55 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 56 | if responseObject.get_key_name() is not None: 57 | print("Error Key Name : " + str(responseObject.get_key_name())) 58 | else: 59 | print('Spreadsheet Creation Request Failed') 60 | 61 | @staticmethod 62 | def init_sdk(): 63 | try: 64 | #Sdk application log configuration 65 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 66 | #Update this apikey with your own apikey signed up in office integrator service 67 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 68 | tokens = [ auth ] 69 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 70 | environment = DataCenter.Production("https://api.office-integrator.com") 71 | 72 | Initializer.initialize(environment, tokens,None, None, logger, None) 73 | except SDKException as ex: 74 | print(ex.code) 75 | 76 | DeleteSpreadsheet.execute() -------------------------------------------------------------------------------- /spreadsheet-apis/DeleteSpreadsheetSession.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 7 | CreateSheetParameters, CreateSheetResponse, SessionDeleteSuccessResponse, Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 9 | 10 | class DeleteSpreadsheetSession: 11 | 12 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-delete-user-session.html 13 | @staticmethod 14 | def execute(): 15 | DeleteSpreadsheetSession.init_sdk() 16 | createSpreadsheetParams = CreateSheetParameters() 17 | 18 | print('Creating a spreadsheet to demonstrate spreadsheet session delete api') 19 | v1Operations = V1Operations() 20 | response = v1Operations.create_sheet(createSpreadsheetParams) 21 | 22 | if response is not None: 23 | print('Status Code: ' + str(response.get_status_code())) 24 | responseObject = response.get_object() 25 | 26 | if responseObject is not None: 27 | if isinstance(responseObject, CreateSheetResponse): 28 | sessionId = str(responseObject.get_session_id()) 29 | print('Spreadsheet session ID to be deleted : ' + sessionId) 30 | 31 | deleteApiResponse = v1Operations.delete_sheet_session(sessionId) 32 | 33 | if deleteApiResponse is not None: 34 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 35 | deleteResponseObject = deleteApiResponse.get_object() 36 | 37 | if deleteResponseObject is not None: 38 | if isinstance(deleteResponseObject, SessionDeleteSuccessResponse): 39 | print('Spreadsheet session delete status : ' + str(deleteResponseObject.get_session_delete())) 40 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 41 | print('Invalid configuration exception.') 42 | print('Error Code : ' + str(deleteResponseObject.get_code())) 43 | print("Error Message : " + str(deleteResponseObject.get_message())) 44 | if deleteResponseObject.get_parameter_name() is not None: 45 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 46 | if deleteResponseObject.get_key_name() is not None: 47 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 48 | else: 49 | print('Delete Spreadsheet Session Request Failed') 50 | elif isinstance(responseObject, InvalidConfigurationException): 51 | print('Invalid configuration exception.') 52 | print('Error Code : ' + str(responseObject.get_code())) 53 | print("Error Message : " + str(responseObject.get_message())) 54 | if responseObject.get_parameter_name() is not None: 55 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 56 | if responseObject.get_key_name() is not None: 57 | print("Error Key Name : " + str(responseObject.get_key_name())) 58 | else: 59 | print('Spreadsheet Creation Request Failed') 60 | 61 | @staticmethod 62 | def init_sdk(): 63 | try: 64 | #Sdk application log configuration 65 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 66 | #Update this apikey with your own apikey signed up in office integrator service 67 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 68 | tokens = [ auth ] 69 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 70 | environment = DataCenter.Production("https://api.office-integrator.com") 71 | 72 | Initializer.initialize(environment, tokens,None, None, logger, None) 73 | except SDKException as ex: 74 | print(ex.code) 75 | 76 | DeleteSpreadsheetSession.execute() -------------------------------------------------------------------------------- /presentation-apis/ConvertPresentation.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.v1 import FileBodyWrapper, InvalidConfigurationException, \ 9 | ConvertPresentationParameters, Authentication 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 11 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 12 | 13 | 14 | class ConvertPresentation: 15 | 16 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/show-conversion-api.html 17 | @staticmethod 18 | def execute(): 19 | ConvertPresentation.init_sdk() 20 | presentationConversionParameters = ConvertPresentationParameters() 21 | 22 | presentationConversionParameters.set_url('https://demo.office-integrator.com/samples/show/Zoho_Show.pptx') 23 | 24 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 25 | # filePath = ROOT_DIR + "/sample_documents/Zoho_Show.pptx" 26 | # print('Path for source file to be edited : ' + filePath) 27 | # presentationConversionParameters.set_document(StreamWrapper(file_path=filePath)) 28 | 29 | presentationConversionParameters.set_format('pdf') 30 | 31 | v1Operations = V1Operations() 32 | response = v1Operations.convert_presentation(presentationConversionParameters) 33 | 34 | if response is not None: 35 | print('Status Code: ' + str(response.get_status_code())) 36 | responseObject = response.get_object() 37 | 38 | if responseObject is not None: 39 | if isinstance(responseObject, FileBodyWrapper): 40 | convertedDocument = responseObject.get_file() 41 | 42 | if isinstance(convertedDocument, StreamWrapper): 43 | outputFileStream = convertedDocument.get_stream() 44 | outputFilePath = ROOT_DIR + "/sample_documents/conversion_output.pdf" 45 | 46 | with open(outputFilePath, 'wb') as outputFileObj: 47 | # while True: 48 | # # Read a chunk of data from the input stream 49 | # chunk = outputFileStream.read(1024) # You can adjust the chunk size as needed 50 | # 51 | # # If no more data is read, break the loop 52 | # if not chunk: 53 | # break 54 | # 55 | # # Write the chunk of data to the file 56 | # outputFileObj.write(chunk) 57 | outputFileObj.write(outputFileStream.content) 58 | 59 | print("\nCheck converted output file in file path - " + outputFilePath) 60 | elif isinstance(responseObject, InvalidConfigurationException): 61 | print('Invalid configuration exception.') 62 | print('Error Code : ' + str(responseObject.get_code())) 63 | print("Error Message : " + str(responseObject.get_message())) 64 | if responseObject.get_parameter_name() is not None: 65 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 66 | if responseObject.get_key_name() is not None: 67 | print("Error Key Name : " + str(responseObject.get_key_name())) 68 | else: 69 | print('Presentation Conversion Request Failed') 70 | 71 | @staticmethod 72 | def init_sdk(): 73 | try: 74 | #Sdk application log configuration 75 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 76 | #Update this apikey with your own apikey signed up in office integrator service 77 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 78 | tokens = [ auth ] 79 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 80 | environment = DataCenter.Production("https://api.office-integrator.com") 81 | 82 | Initializer.initialize(environment, tokens,None, None, logger, None) 83 | except SDKException as ex: 84 | print(ex.code) 85 | 86 | 87 | ConvertPresentation.execute() 88 | -------------------------------------------------------------------------------- /presentation-apis/DeletePresentation.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 7 | CreatePresentationParameters, FileDeleteSuccessResponse, Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | class DeletePresentation: 12 | 13 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-show-delete-presentation.html 14 | @staticmethod 15 | def execute(): 16 | DeletePresentation.init_sdk() 17 | createPresentationParams = CreatePresentationParameters() 18 | 19 | print('Creating a presentation to demonstrate presentation delete api') 20 | v1Operations = V1Operations() 21 | response = v1Operations.create_presentation(createPresentationParams) 22 | 23 | if response is not None: 24 | print('Status Code: ' + str(response.get_status_code())) 25 | responseObject = response.get_object() 26 | 27 | if responseObject is not None: 28 | if isinstance(responseObject, CreateDocumentResponse): 29 | presentationId = str(responseObject.get_document_id()) 30 | print('Presentation Session ID to be deleted : ' + presentationId) 31 | 32 | deleteApiResponse = v1Operations.delete_presentation(presentationId) 33 | 34 | if deleteApiResponse is not None: 35 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 36 | deleteResponseObject = deleteApiResponse.get_object() 37 | 38 | if deleteResponseObject is not None: 39 | if isinstance(deleteResponseObject, FileDeleteSuccessResponse): 40 | print('Presentation delete status : ' + str(deleteResponseObject.get_doc_delete())) 41 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 42 | print('Invalid configuration exception.') 43 | print('Error Code : ' + str(deleteResponseObject.get_code())) 44 | print("Error Message : " + str(deleteResponseObject.get_message())) 45 | if deleteResponseObject.get_parameter_name() is not None: 46 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 47 | if deleteResponseObject.get_key_name() is not None: 48 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 49 | else: 50 | print('Delete Presentation Session Request Failed') 51 | elif isinstance(responseObject, InvalidConfigurationException): 52 | print('Invalid configuration exception.') 53 | print('Error Code : ' + str(responseObject.get_code())) 54 | print("Error Message : " + str(responseObject.get_message())) 55 | if responseObject.get_parameter_name() is not None: 56 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 57 | if responseObject.get_key_name() is not None: 58 | print("Error Key Name : " + str(responseObject.get_key_name())) 59 | else: 60 | print('Presentation Creation Request Failed') 61 | 62 | @staticmethod 63 | def init_sdk(): 64 | try: 65 | #Sdk application log configuration 66 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 67 | #Update this apikey with your own apikey signed up in office integrator service 68 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 69 | tokens = [ auth ] 70 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 71 | environment = DataCenter.Production("https://api.office-integrator.com") 72 | 73 | Initializer.initialize(environment, tokens,None, None, logger, None) 74 | except SDKException as ex: 75 | print(ex.code) 76 | 77 | DeletePresentation.execute() -------------------------------------------------------------------------------- /document-apis/DeleteDocument.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentDeleteSuccessResponse, \ 7 | InvalidConfigurationException, Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_parameters import CreateDocumentParameters 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 11 | 12 | class DeleteDocument: 13 | 14 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-delete-document.html 15 | @staticmethod 16 | def execute(): 17 | DeleteDocument.init_sdk() 18 | createDocumentParams = CreateDocumentParameters() 19 | 20 | print('Creating a document to demonstrate document delete api') 21 | v1Operations = V1Operations() 22 | response = v1Operations.create_document(createDocumentParams) 23 | 24 | if response is not None: 25 | print('Status Code: ' + str(response.get_status_code())) 26 | responseObject = response.get_object() 27 | 28 | if responseObject is not None: 29 | if isinstance(responseObject, CreateDocumentResponse): 30 | documentId = str(responseObject.get_document_id()) 31 | print('Document ID to be deleted : ' + documentId) 32 | 33 | deleteApiResponse = v1Operations.delete_document(documentId) 34 | 35 | if deleteApiResponse is not None: 36 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 37 | deleteResponseObject = deleteApiResponse.get_object() 38 | 39 | if deleteResponseObject is not None: 40 | if isinstance(deleteResponseObject, DocumentDeleteSuccessResponse): 41 | print('Document delete status : ' + str(deleteResponseObject.get_document_deleted())) 42 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 43 | print('Invalid configuration exception.') 44 | print('Error Code : ' + str(deleteResponseObject.get_code())) 45 | print("Error Message : " + str(deleteResponseObject.get_message())) 46 | if deleteResponseObject.get_parameter_name() is not None: 47 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 48 | if deleteResponseObject.get_key_name() is not None: 49 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 50 | else: 51 | print('Delete Document Request Failed') 52 | elif isinstance(responseObject, InvalidConfigurationException): 53 | print('Invalid configuration exception.') 54 | print('Error Code : ' + str(responseObject.get_code())) 55 | print("Error Message : " + str(responseObject.get_message())) 56 | if responseObject.get_parameter_name() is not None: 57 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 58 | if responseObject.get_key_name() is not None: 59 | print("Error Key Name : " + str(responseObject.get_key_name())) 60 | else: 61 | print('Document Creation Request Failed') 62 | 63 | @staticmethod 64 | def init_sdk(): 65 | try: 66 | #Sdk application log configuration 67 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 68 | #Update this apikey with your own apikey signed up in office integrator service 69 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 70 | tokens = [ auth ] 71 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 72 | environment = DataCenter.Production("https://api.office-integrator.com") 73 | 74 | Initializer.initialize(environment, tokens,None, None, logger, None) 75 | except SDKException as ex: 76 | print(ex.code) 77 | 78 | DeleteDocument.execute() 79 | -------------------------------------------------------------------------------- /presentation-apis/DeletePresentationSession.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 7 | CreatePresentationParameters, SessionDeleteSuccessResponse, Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | class DeletePresentationSession: 12 | 13 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-show-delete-user-session.html 14 | @staticmethod 15 | def execute(): 16 | DeletePresentationSession.init_sdk() 17 | createPresentationParams = CreatePresentationParameters() 18 | 19 | print('Creating a presentation to demonstrate presentation session delete api') 20 | v1Operations = V1Operations() 21 | response = v1Operations.create_presentation(createPresentationParams) 22 | 23 | if response is not None: 24 | print('Status Code: ' + str(response.get_status_code())) 25 | responseObject = response.get_object() 26 | 27 | if responseObject is not None: 28 | if isinstance(responseObject, CreateDocumentResponse): 29 | documentSessionId = str(responseObject.get_session_id()) 30 | print('Presentation Session ID to be deleted : ' + documentSessionId) 31 | 32 | deleteApiResponse = v1Operations.delete_presentation_session(documentSessionId) 33 | 34 | if deleteApiResponse is not None: 35 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 36 | deleteResponseObject = deleteApiResponse.get_object() 37 | 38 | if deleteResponseObject is not None: 39 | if isinstance(deleteResponseObject, SessionDeleteSuccessResponse): 40 | print('Presentation Session delete status : ' + str(deleteResponseObject.get_session_delete())) 41 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 42 | print('Invalid configuration exception.') 43 | print('Error Code : ' + str(deleteResponseObject.get_code())) 44 | print("Error Message : " + str(deleteResponseObject.get_message())) 45 | if deleteResponseObject.get_parameter_name() is not None: 46 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 47 | if deleteResponseObject.get_key_name() is not None: 48 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 49 | else: 50 | print('Delete Presentation Session Request Failed') 51 | elif isinstance(responseObject, InvalidConfigurationException): 52 | print('Invalid configuration exception.') 53 | print('Error Code : ' + str(responseObject.get_code())) 54 | print("Error Message : " + str(responseObject.get_message())) 55 | if responseObject.get_parameter_name() is not None: 56 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 57 | if responseObject.get_key_name() is not None: 58 | print("Error Key Name : " + str(responseObject.get_key_name())) 59 | else: 60 | print('Presentation Creation Request Failed') 61 | 62 | @staticmethod 63 | def init_sdk(): 64 | try: 65 | #Sdk application log configuration 66 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 67 | #Update this apikey with your own apikey signed up in office integrator service 68 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 69 | tokens = [ auth ] 70 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 71 | environment = DataCenter.Production("https://api.office-integrator.com") 72 | 73 | Initializer.initialize(environment, tokens,None, None, logger, None) 74 | except SDKException as ex: 75 | print(ex.code) 76 | 77 | DeletePresentationSession.execute() -------------------------------------------------------------------------------- /document-apis/DeleteDocumentSession.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | 7 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentSessionDeleteSuccessResponse, \ 8 | InvalidConfigurationException, Authentication 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_parameters import CreateDocumentParameters 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | class DeleteDocumentSession: 14 | 15 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-delete-user-session.html 16 | @staticmethod 17 | def execute(): 18 | DeleteDocumentSession.init_sdk() 19 | createDocumentParams = CreateDocumentParameters() 20 | 21 | print('Creating a document to demonstrate document session delete api') 22 | v1Operations = V1Operations() 23 | response = v1Operations.create_document(createDocumentParams) 24 | 25 | if response is not None: 26 | print('Status Code: ' + str(response.get_status_code())) 27 | responseObject = response.get_object() 28 | 29 | if responseObject is not None: 30 | if isinstance(responseObject, CreateDocumentResponse): 31 | documentSessionId = str(responseObject.get_session_id()) 32 | print('Document Session ID to be deleted : ' + documentSessionId) 33 | 34 | deleteApiResponse = v1Operations.delete_session(documentSessionId) 35 | 36 | if deleteApiResponse is not None: 37 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 38 | deleteResponseObject = deleteApiResponse.get_object() 39 | 40 | if deleteResponseObject is not None: 41 | if isinstance(deleteResponseObject, DocumentSessionDeleteSuccessResponse): 42 | print('Document Session delete status : ' + str(deleteResponseObject.get_session_deleted())) 43 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 44 | print('Invalid configuration exception.') 45 | print('Error Code : ' + str(deleteResponseObject.get_code())) 46 | print("Error Message : " + str(deleteResponseObject.get_message())) 47 | if deleteResponseObject.get_parameter_name() is not None: 48 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 49 | if deleteResponseObject.get_key_name() is not None: 50 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 51 | else: 52 | print('Delete Document Session Request Failed') 53 | elif isinstance(responseObject, InvalidConfigurationException): 54 | print('Invalid configuration exception.') 55 | print('Error Code : ' + str(responseObject.get_code())) 56 | print("Error Message : " + str(responseObject.get_message())) 57 | if responseObject.get_parameter_name() is not None: 58 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 59 | if responseObject.get_key_name() is not None: 60 | print("Error Key Name : " + str(responseObject.get_key_name())) 61 | else: 62 | print('Document Creation Request Failed') 63 | 64 | @staticmethod 65 | def init_sdk(): 66 | try: 67 | #Sdk application log configuration 68 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 69 | #Update this apikey with your own apikey signed up in office integrator service 70 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 71 | tokens = [ auth ] 72 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 73 | environment = DataCenter.Production("https://api.office-integrator.com") 74 | 75 | Initializer.initialize(environment, tokens,None, None, logger, None) 76 | except SDKException as ex: 77 | print(ex.code) 78 | 79 | DeleteDocumentSession.execute() 80 | -------------------------------------------------------------------------------- /pdf-apis/DeletePdfDocument.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentDeleteSuccessResponse, \ 7 | InvalidConfigurationException, Authentication, EditPdfParameters 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | class DeleteDocument: 12 | 13 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-pdfeditor-delete-pdf.html 14 | @staticmethod 15 | def execute(): 16 | DeleteDocument.init_sdk() 17 | editDocumentParams = EditPdfParameters() 18 | 19 | # Either use url as document source or attach the document in request body use below methods 20 | editDocumentParams.set_url('https://demo.office-integrator.com/zdocs/BusinessIntelligence.pdf') 21 | 22 | print('Creating a document to demonstrate document delete api') 23 | v1Operations = V1Operations() 24 | response = v1Operations.edit_pdf(editDocumentParams) 25 | 26 | if response is not None: 27 | print('Status Code: ' + str(response.get_status_code())) 28 | responseObject = response.get_object() 29 | 30 | if responseObject is not None: 31 | if isinstance(responseObject, CreateDocumentResponse): 32 | documentId = str(responseObject.get_document_id()) 33 | print('Document ID to be deleted : ' + documentId) 34 | 35 | deleteApiResponse = v1Operations.delete_pdf_document(documentId) 36 | 37 | if deleteApiResponse is not None: 38 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 39 | deleteResponseObject = deleteApiResponse.get_object() 40 | 41 | if deleteResponseObject is not None: 42 | if isinstance(deleteResponseObject, DocumentDeleteSuccessResponse): 43 | print('PDF Document delete status : ' + str(deleteResponseObject.get_document_deleted())) 44 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 45 | print('Invalid configuration exception.') 46 | print('Error Code : ' + str(deleteResponseObject.get_code())) 47 | print("Error Message : " + str(deleteResponseObject.get_message())) 48 | if deleteResponseObject.get_parameter_name() is not None: 49 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 50 | if deleteResponseObject.get_key_name() is not None: 51 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 52 | else: 53 | print('Delete PDF Document Request Failed') 54 | elif isinstance(responseObject, InvalidConfigurationException): 55 | print('Invalid configuration exception.') 56 | print('Error Code : ' + str(responseObject.get_code())) 57 | print("Error Message : " + str(responseObject.get_message())) 58 | if responseObject.get_parameter_name() is not None: 59 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 60 | if responseObject.get_key_name() is not None: 61 | print("Error Key Name : " + str(responseObject.get_key_name())) 62 | else: 63 | print('Document PDF Session Creation Request Failed') 64 | 65 | @staticmethod 66 | def init_sdk(): 67 | try: 68 | #Sdk application log configuration 69 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 70 | #Update this apikey with your own apikey signed up in office integrator service 71 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 72 | tokens = [ auth ] 73 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 74 | environment = DataCenter.Production("https://api.office-integrator.com") 75 | 76 | Initializer.initialize(environment, tokens,None, None, logger, None) 77 | except SDKException as ex: 78 | print(ex.code) 79 | 80 | DeleteDocument.execute() 81 | -------------------------------------------------------------------------------- /document-apis/CombinePdf.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentConversionParameters, \ 9 | DocumentConversionOutputOptions, \ 10 | FileBodyWrapper, InvalidConfigurationException, Authentication, CombinePdfParameters, CombinePdfOutputSettings 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 13 | 14 | class CombinePdf: 15 | 16 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-combine-pdfs.html 17 | @staticmethod 18 | def execute(): 19 | CombinePdf.init_sdk() 20 | combinePdfParameters = CombinePdfParameters() 21 | 22 | files = [] 23 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 24 | filePath1 = ROOT_DIR + "/sample_documents/Document1.pdf" 25 | print('Source file to be converted : ' + filePath1) 26 | files.append(StreamWrapper(file_path=filePath1)) 27 | 28 | filePath2 = ROOT_DIR + "/sample_documents/Document2.pdf" 29 | print('Source file to be combined : ' + filePath2) 30 | files.append(StreamWrapper(file_path=filePath2)) 31 | 32 | combinePdfParameters.set_files(files) 33 | 34 | outputOptions = CombinePdfOutputSettings() 35 | 36 | outputOptions.set_name("combine_output.pdf") 37 | 38 | combinePdfParameters.set_output_settings(outputOptions) 39 | 40 | v1Operations = V1Operations() 41 | response = v1Operations.combine_pdf(combinePdfParameters) 42 | 43 | if response is not None: 44 | print('Status Code: ' + str(response.get_status_code())) 45 | responseObject = response.get_object() 46 | 47 | if responseObject is not None: 48 | if isinstance(responseObject, FileBodyWrapper): 49 | convertedDocument = responseObject.get_file() 50 | 51 | if isinstance(convertedDocument, StreamWrapper): 52 | outputFileStream = convertedDocument.get_stream() 53 | outputFilePath = ROOT_DIR + "/sample_documents/combine_output.pdf" 54 | 55 | with open(outputFilePath, 'wb') as outputFileObj: 56 | # while True: 57 | # # Read a chunk of data from the input stream 58 | # chunk = outputFileStream.read(1024) # You can adjust the chunk size as needed 59 | # 60 | # # If no more data is read, break the loop 61 | # if not chunk: 62 | # break 63 | # 64 | # # Write the chunk of data to the file 65 | # outputFileObj.write(chunk) 66 | outputFileObj.write(outputFileStream.content) 67 | 68 | print("\nCheck combined pdf output file in file path - " + outputFilePath) 69 | elif isinstance(responseObject, InvalidConfigurationException): 70 | print('Invalid configuration exception.') 71 | print('Error Code : ' + str(responseObject.get_code())) 72 | print("Error Message : " + str(responseObject.get_message())) 73 | if responseObject.get_parameter_name() is not None: 74 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 75 | if responseObject.get_key_name() is not None: 76 | print("Error Key Name : " + str(responseObject.get_key_name())) 77 | else: 78 | print('Document Conversion Request Failed') 79 | 80 | @staticmethod 81 | def init_sdk(): 82 | try: 83 | #Sdk application log configuration 84 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 85 | #Update this apikey with your own apikey signed up in office integrator service 86 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 87 | tokens = [ auth ] 88 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 89 | environment = DataCenter.Production("https://api.office-integrator.com") 90 | 91 | Initializer.initialize(environment, tokens,None, None, logger, None) 92 | except SDKException as ex: 93 | print(ex.code) 94 | 95 | 96 | CombinePdf.execute() 97 | -------------------------------------------------------------------------------- /spreadsheet-apis/ConvertSpreadsheet.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 7 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 8 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 9 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 10 | SheetConversionParameters, SheetConversionOutputOptions, FileBodyWrapper, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | class ConvertSpreadsheet: 14 | 15 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/sheet-conversion-api.html 16 | @staticmethod 17 | def execute(): 18 | ConvertSpreadsheet.init_sdk() 19 | sheetConversionParameters = SheetConversionParameters() 20 | 21 | # Either use url as document source or attach the document in request body use below methods 22 | sheetConversionParameters.set_url('https://demo.office-integrator.com/samples/sheet/Contact_List.xlsx') 23 | 24 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 25 | # filePath = ROOT_DIR + "/sample_documents/Contact_List.xlsx" 26 | # print('Path for source file to be edited : ' + filePath) 27 | # sheetConversionParameters.set_document(StreamWrapper(file_path=filePath)) 28 | 29 | outputOptions = SheetConversionOutputOptions() 30 | 31 | outputOptions.set_format('pdf') 32 | outputOptions.set_document_name('ConvertedSheet.pdf') 33 | 34 | sheetConversionParameters.set_output_options(outputOptions) 35 | 36 | v1Operations = V1Operations() 37 | response = v1Operations.convert_sheet(sheetConversionParameters) 38 | 39 | if response is not None: 40 | print('Status Code: ' + str(response.get_status_code())) 41 | responseObject = response.get_object() 42 | 43 | if responseObject is not None: 44 | if isinstance(responseObject, FileBodyWrapper): 45 | convertedDocument = responseObject.get_file() 46 | 47 | if isinstance(convertedDocument, StreamWrapper): 48 | outputFileStream = convertedDocument.get_stream() 49 | outputFilePath = ROOT_DIR + "/sample_documents/conversion_output.pdf" 50 | 51 | with open(outputFilePath, 'wb') as outputFileObj: 52 | # while True: 53 | # # Read a chunk of data from the input stream 54 | # chunk = outputFileStream.read(1024) # You can adjust the chunk size as needed 55 | # 56 | # # If no more data is read, break the loop 57 | # if not chunk: 58 | # break 59 | # 60 | # # Write the chunk of data to the file 61 | # outputFileObj.write(chunk) 62 | outputFileObj.write(outputFileStream.content) 63 | 64 | print("\nCheck converted output file in file path - " + outputFilePath) 65 | elif isinstance(responseObject, InvalidConfigurationException): 66 | print('Invalid configuration exception.') 67 | print('Error Code : ' + str(responseObject.get_code())) 68 | print("Error Message : " + str(responseObject.get_message())) 69 | if responseObject.get_parameter_name() is not None: 70 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 71 | if responseObject.get_key_name() is not None: 72 | print("Error Key Name : " + str(responseObject.get_key_name())) 73 | else: 74 | print('Spreadsheet Conversion Request Failed') 75 | 76 | @staticmethod 77 | def init_sdk(): 78 | try: 79 | #Sdk application log configuration 80 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 81 | #Update this apikey with your own apikey signed up in office integrator service 82 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 83 | tokens = [ auth ] 84 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 85 | environment = DataCenter.Production("https://api.office-integrator.com") 86 | 87 | Initializer.initialize(environment, tokens,None, None, logger, None) 88 | except SDKException as ex: 89 | print(ex.code) 90 | 91 | ConvertSpreadsheet.execute() -------------------------------------------------------------------------------- /pdf-apis/DeletePdfDocumentSession.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | 7 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentSessionDeleteSuccessResponse, \ 8 | InvalidConfigurationException, Authentication, EditPdfParameters 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 11 | 12 | class DeletePdfDocumentSession: 13 | 14 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-pdfeditor-delete-session.html 15 | @staticmethod 16 | def execute(): 17 | DeletePdfDocumentSession.init_sdk() 18 | editDocumentParams = EditPdfParameters() 19 | 20 | # Either use url as document source or attach the document in request body use below methods 21 | editDocumentParams.set_url('https://demo.office-integrator.com/zdocs/BusinessIntelligence.pdf') 22 | 23 | print('Creating a document to demonstrate document session delete api') 24 | v1Operations = V1Operations() 25 | response = v1Operations.edit_pdf(editDocumentParams) 26 | 27 | if response is not None: 28 | print('Status Code: ' + str(response.get_status_code())) 29 | responseObject = response.get_object() 30 | 31 | if responseObject is not None: 32 | if isinstance(responseObject, CreateDocumentResponse): 33 | documentSessionId = str(responseObject.get_session_id()) 34 | print('Document Session ID to be deleted : ' + documentSessionId) 35 | 36 | deleteApiResponse = v1Operations.delete_session(documentSessionId) 37 | 38 | if deleteApiResponse is not None: 39 | print('Status Code: ' + str(deleteApiResponse.get_status_code())) 40 | deleteResponseObject = deleteApiResponse.get_object() 41 | 42 | if deleteResponseObject is not None: 43 | if isinstance(deleteResponseObject, DocumentSessionDeleteSuccessResponse): 44 | print('PDF Document Session delete status : ' + str(deleteResponseObject.get_session_deleted())) 45 | elif isinstance(deleteResponseObject, InvalidConfigurationException): 46 | print('Invalid configuration exception.') 47 | print('Error Code : ' + str(deleteResponseObject.get_code())) 48 | print("Error Message : " + str(deleteResponseObject.get_message())) 49 | if deleteResponseObject.get_parameter_name() is not None: 50 | print("Error Parameter Name : " + str(deleteResponseObject.get_parameter_name())) 51 | if deleteResponseObject.get_key_name() is not None: 52 | print("Error Key Name : " + str(deleteResponseObject.get_key_name())) 53 | else: 54 | print('Delete PDF Document Session Request Failed') 55 | elif isinstance(responseObject, InvalidConfigurationException): 56 | print('Invalid configuration exception.') 57 | print('Error Code : ' + str(responseObject.get_code())) 58 | print("Error Message : " + str(responseObject.get_message())) 59 | if responseObject.get_parameter_name() is not None: 60 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 61 | if responseObject.get_key_name() is not None: 62 | print("Error Key Name : " + str(responseObject.get_key_name())) 63 | else: 64 | print('PDF Document Session Creation Request Failed') 65 | 66 | @staticmethod 67 | def init_sdk(): 68 | try: 69 | #Sdk application log configuration 70 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 71 | #Update this apikey with your own apikey signed up in office integrator service 72 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 73 | tokens = [ auth ] 74 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 75 | environment = DataCenter.Production("https://api.office-integrator.com") 76 | 77 | Initializer.initialize(environment, tokens,None, None, logger, None) 78 | except SDKException as ex: 79 | print(ex.code) 80 | 81 | DeletePdfDocumentSession.execute() 82 | -------------------------------------------------------------------------------- /document-apis/WatermarkDocument.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 5 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 6 | from officeintegrator.src.com.zoho.officeintegrator.exception import SDKException 7 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 8 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 9 | from officeintegrator.src.com.zoho.officeintegrator.v1 import WatermarkParameters, WatermarkSettings, V1Operations, \ 10 | FileBodyWrapper, InvalidConfigurationException, Authentication 11 | 12 | class WatermarkDocument: 13 | 14 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/watermark-with-text.html 15 | @staticmethod 16 | def execute(): 17 | WatermarkDocument.init_sdk() 18 | watermarkParameter = WatermarkParameters() 19 | 20 | #Either use url as document source or attach the document in request body use below methods 21 | watermarkParameter.set_url('https://demo.office-integrator.com/zdocs/Graphic-Design-Proposal.docx') 22 | 23 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 24 | # filePath = ROOT_DIR + "/sample_documents/Graphic-Design-Proposal.docx" 25 | # print('Path for source file to be edited : ' + filePath) 26 | # watermarkParameter.set_document(StreamWrapper(file_path=filePath)) 27 | 28 | watermarkSettings = WatermarkSettings() 29 | 30 | watermarkSettings.set_type("text") 31 | watermarkSettings.set_font_size(18) 32 | watermarkSettings.set_opacity(70.00) 33 | watermarkSettings.set_font_name("Arial") 34 | watermarkSettings.set_font_color("#cd4544") 35 | watermarkSettings.set_orientation("horizontal") 36 | watermarkSettings.set_text("Sample Water Mark Text") 37 | 38 | watermarkParameter.set_watermark_settings(watermarkSettings) 39 | 40 | v1Operations = V1Operations() 41 | response = v1Operations.create_watermark_document(watermarkParameter) 42 | 43 | if response is not None: 44 | print('Status Code: ' + str(response.get_status_code())) 45 | responseObject = response.get_object() 46 | 47 | if responseObject is not None: 48 | if isinstance(responseObject, FileBodyWrapper): 49 | convertedDocument = responseObject.get_file() 50 | 51 | if isinstance(convertedDocument, StreamWrapper): 52 | outputFileStream = convertedDocument.get_stream() 53 | outputFilePath = ROOT_DIR + "/sample_documents/watermark_output.docx" 54 | 55 | with open(outputFilePath, 'wb') as outputFileObj: 56 | # while True: 57 | # # Read a chunk of data from the input stream 58 | # chunk = outputFileStream.read(1024) # You can adjust the chunk size as needed 59 | # 60 | # # If no more data is read, break the loop 61 | # if not chunk: 62 | # break 63 | # 64 | # # Write the chunk of data to the file 65 | # outputFileObj.write(chunk) 66 | outputFileObj.write(outputFileStream.content) 67 | 68 | print("\nCheck Watermark output file in file path - " + outputFilePath) 69 | elif isinstance(responseObject, InvalidConfigurationException): 70 | print('Invalid configuration exception.') 71 | print('Error Code : ' + str(responseObject.get_code())) 72 | print("Error Message : " + str(responseObject.get_message())) 73 | if responseObject.get_parameter_name() is not None: 74 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 75 | if responseObject.get_key_name() is not None: 76 | print("Error Key Name : " + str(responseObject.get_key_name())) 77 | else: 78 | print('Document Conversion Request Failed') 79 | 80 | @staticmethod 81 | def init_sdk(): 82 | try: 83 | #Sdk application log configuration 84 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 85 | #Update this apikey with your own apikey signed up in office integrator service 86 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 87 | tokens = [ auth ] 88 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 89 | environment = DataCenter.Production("https://api.office-integrator.com") 90 | 91 | Initializer.initialize(environment, tokens,None, None, logger, None) 92 | except SDKException as ex: 93 | print(ex.code) 94 | 95 | WatermarkDocument.execute() -------------------------------------------------------------------------------- /document-apis/ConvertDocument.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentConversionParameters, \ 9 | DocumentConversionOutputOptions, \ 10 | FileBodyWrapper, InvalidConfigurationException, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 13 | 14 | class ConvertDocument: 15 | 16 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/writer-conversion-api.html 17 | @staticmethod 18 | def execute(): 19 | ConvertDocument.init_sdk() 20 | documentConversionParameters = DocumentConversionParameters() 21 | 22 | # Either use url as document source or attach the document in request body use below methods 23 | documentConversionParameters.set_url('https://demo.office-integrator.com/zdocs/Graphic-Design-Proposal.docx') 24 | 25 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 26 | # filePath = ROOT_DIR + "/sample_documents/Graphic-Design-Proposal.docx" 27 | # print('Source file to be converted : ' + filePath) 28 | # documentConversionParameters.set_document(StreamWrapper(file_path=filePath)) 29 | 30 | outputOptions = DocumentConversionOutputOptions() 31 | 32 | outputOptions.set_format("pdf") 33 | outputOptions.set_document_name("conversion_output.pdf") 34 | outputOptions.set_include_comments("all") 35 | outputOptions.set_include_changes("all") 36 | 37 | documentConversionParameters.set_output_options(outputOptions) 38 | documentConversionParameters.set_password("***") 39 | 40 | v1Operations = V1Operations() 41 | response = v1Operations.convert_document(documentConversionParameters) 42 | 43 | if response is not None: 44 | print('Status Code: ' + str(response.get_status_code())) 45 | responseObject = response.get_object() 46 | 47 | if responseObject is not None: 48 | if isinstance(responseObject, FileBodyWrapper): 49 | convertedDocument = responseObject.get_file() 50 | 51 | if isinstance(convertedDocument, StreamWrapper): 52 | outputFileStream = convertedDocument.get_stream() 53 | outputFilePath = ROOT_DIR + "/sample_documents/conversion_output.pdf" 54 | 55 | with open(outputFilePath, 'wb') as outputFileObj: 56 | # while True: 57 | # # Read a chunk of data from the input stream 58 | # chunk = outputFileStream.read(1024) # You can adjust the chunk size as needed 59 | # 60 | # # If no more data is read, break the loop 61 | # if not chunk: 62 | # break 63 | # 64 | # # Write the chunk of data to the file 65 | # outputFileObj.write(chunk) 66 | outputFileObj.write(outputFileStream.content) 67 | 68 | print("\nCheck converted output file in file path - " + outputFilePath) 69 | elif isinstance(responseObject, InvalidConfigurationException): 70 | print('Invalid configuration exception.') 71 | print('Error Code : ' + str(responseObject.get_code())) 72 | print("Error Message : " + str(responseObject.get_message())) 73 | if responseObject.get_parameter_name() is not None: 74 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 75 | if responseObject.get_key_name() is not None: 76 | print("Error Key Name : " + str(responseObject.get_key_name())) 77 | else: 78 | print('Document Conversion Request Failed') 79 | 80 | @staticmethod 81 | def init_sdk(): 82 | try: 83 | #Sdk application log configuration 84 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 85 | #Update this apikey with your own apikey signed up in office integrator service 86 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 87 | tokens = [ auth ] 88 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 89 | environment = DataCenter.Production("https://api.office-integrator.com") 90 | 91 | Initializer.initialize(environment, tokens,None, None, logger, None) 92 | except SDKException as ex: 93 | print(ex.code) 94 | 95 | 96 | ConvertDocument.execute() 97 | -------------------------------------------------------------------------------- /spreadsheet-apis/GetSessionDetails.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import SessionInfo, \ 7 | SessionMeta, InvalidConfigurationException, CreateSheetParameters, \ 8 | CreateSheetResponse, Authentication 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | class GetSessionDetails: 12 | 13 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-session-information.html 14 | @staticmethod 15 | def execute(): 16 | GetSessionDetails.init_sdk() 17 | createSpreadsheetParams = CreateSheetParameters() 18 | 19 | print('Creating a spreadsheet to demonstrate get spreadsheet session information api') 20 | v1Operations = V1Operations() 21 | response = v1Operations.create_sheet(createSpreadsheetParams) 22 | 23 | if response is not None: 24 | print('Status Code: ' + str(response.get_status_code())) 25 | responseObject = response.get_object() 26 | 27 | if responseObject is not None: 28 | if isinstance(responseObject, CreateSheetResponse): 29 | sessionId = str(responseObject.get_session_id()) 30 | print('Created Spreadsheet Session ID : ' + sessionId) 31 | 32 | sessionInfoResponse = v1Operations.get_sheet_session(sessionId) 33 | 34 | if sessionInfoResponse is not None: 35 | print('Status Code: ' + str(sessionInfoResponse.get_status_code())) 36 | sessionInfoObj = sessionInfoResponse.get_object() 37 | 38 | if sessionInfoObj is not None: 39 | if isinstance(sessionInfoObj, SessionMeta): 40 | print('Session Status : ' + str(sessionInfoObj.get_status())) 41 | 42 | sessionInfo = sessionInfoObj.get_info() 43 | 44 | if isinstance(sessionInfo, SessionInfo): 45 | print('Spreadsheet ID : ' + str(sessionInfo.get_document_id())) 46 | print('Spreadsheet Session Created Time : ' + str(sessionInfo.get_created_time())) 47 | print('Spreadsheet Session Created Timestamp : ' + str(sessionInfo.get_created_time_ms())) 48 | print('Spreadsheet Session Expiry Time : ' + str(sessionInfo.get_expires_on())) 49 | print('Spreadsheet Session Expiry Timestamp : ' + str(sessionInfo.get_expires_on_ms())) 50 | elif isinstance(sessionInfoObj, InvalidConfigurationException): 51 | print('Invalid configuration exception.') 52 | print('Error Code : ' + str(sessionInfoObj.get_code())) 53 | print("Error Message : " + str(sessionInfoObj.get_message())) 54 | if sessionInfoObj.get_parameter_name() is not None: 55 | print("Error Parameter Name : " + str(sessionInfoObj.get_parameter_name())) 56 | if sessionInfoObj.get_key_name() is not None: 57 | print("Error Key Name : " + str(sessionInfoObj.get_key_name())) 58 | else: 59 | print('Get Spreadsheet Session Details Request Failed') 60 | elif isinstance(responseObject, InvalidConfigurationException): 61 | print('Invalid configuration exception.') 62 | print('Error Code : ' + str(responseObject.get_code())) 63 | print("Error Message : " + str(responseObject.get_message())) 64 | if responseObject.get_parameter_name() is not None: 65 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 66 | if responseObject.get_key_name() is not None: 67 | print("Error Key Name : " + str(responseObject.get_key_name())) 68 | else: 69 | print('Create Spreadsheet Request Failed') 70 | 71 | @staticmethod 72 | def init_sdk(): 73 | try: 74 | #Sdk application log configuration 75 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 76 | #Update this apikey with your own apikey signed up in office integrator service 77 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 78 | tokens = [ auth ] 79 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 80 | environment = DataCenter.Production("https://api.office-integrator.com") 81 | 82 | Initializer.initialize(environment, tokens,None, None, logger, None) 83 | except SDKException as ex: 84 | print(ex.code) 85 | 86 | 87 | GetSessionDetails.execute() 88 | -------------------------------------------------------------------------------- /document-apis/MergeAndDownload.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 7 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 8 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 9 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 10 | MergeAndDownloadDocumentParameters, FileBodyWrapper, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | class MergeAndDownload: 14 | 15 | # Refer Preview API documentation - https://www.zoho.com/officeintegrator/api/v1/merge-document.html 16 | @staticmethod 17 | def execute(): 18 | MergeAndDownload.init_sdk() 19 | parameter = MergeAndDownloadDocumentParameters() 20 | 21 | # Either use url as document source or attach the document in request body use below methods 22 | parameter.set_file_url('https://demo.office-integrator.com/zdocs/OfferLetter.zdoc') 23 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 24 | # filePath = ROOT_DIR + "/sample_documents/OfferLetter.zdoc" 25 | # print('Source document file path : ' + filePath) 26 | # parameter.set_file_content(StreamWrapper(file_path=filePath)) 27 | 28 | parameter.set_merge_data_json_url("https://demo.office-integrator.com/data/candidates.json") 29 | # jsonFilePath = ROOT_DIR + "/sample_documents/candidates.json" 30 | # print('Data Source Json file to be path : ' + jsonFilePath) 31 | # parameter.set_merge_data_json_content(StreamWrapper(file_path=jsonFilePath)) 32 | 33 | # parameter.set_merge_data_csv_url("https://demo.office-integrator.com/data/csv_data_source.csv") 34 | # filePath = ROOT_DIR + "/sample_documents/csv_data_source.csv" 35 | # print('Source document file path : ' + filePath) 36 | # parameter.set_merge_data_csv_content(StreamWrapper(file_path=filePath)) 37 | 38 | parameter.set_output_format('pdf') 39 | parameter.set_password('***') 40 | 41 | v1Operations = V1Operations() 42 | response = v1Operations.merge_and_download_document(parameter) 43 | 44 | if response is not None: 45 | print('Status Code: ' + str(response.get_status_code())) 46 | responseObject = response.get_object() 47 | 48 | if responseObject is not None: 49 | if isinstance(responseObject, FileBodyWrapper): 50 | convertedDocument = responseObject.get_file() 51 | 52 | if isinstance(convertedDocument, StreamWrapper): 53 | outputFileStream = convertedDocument.get_stream() 54 | outputFilePath = ROOT_DIR + "/sample_documents/merge_output.pdf" 55 | 56 | with open(outputFilePath, 'wb') as outputFileObj: 57 | # while True: 58 | # # Read a chunk of data from the input stream 59 | # chunk = outputFileStream.read(1024) # You can adjust the chunk size as needed 60 | # 61 | # # If no more data is read, break the loop 62 | # if not chunk: 63 | # break 64 | # 65 | # # Write the chunk of data to the file 66 | # outputFileObj.write(chunk) 67 | outputFileObj.write(outputFileStream.content) 68 | 69 | print("\nCheck converted output file in file path - " + outputFilePath) 70 | elif isinstance(responseObject, InvalidConfigurationException): 71 | print('Invalid configuration exception.') 72 | print('Error Code : ' + str(responseObject.get_code())) 73 | print("Error Message : " + str(responseObject.get_message())) 74 | if responseObject.get_parameter_name() is not None: 75 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 76 | if responseObject.get_key_name() is not None: 77 | print("Error Key Name : " + str(responseObject.get_key_name())) 78 | else: 79 | print('Document Conversion Request Failed') 80 | 81 | @staticmethod 82 | def init_sdk(): 83 | try: 84 | #Sdk application log configuration 85 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 86 | #Update this apikey with your own apikey signed up in office integrator service 87 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 88 | tokens = [ auth ] 89 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 90 | environment = DataCenter.Production("https://api.office-integrator.com") 91 | 92 | Initializer.initialize(environment, tokens,None, None, logger, None) 93 | except SDKException as ex: 94 | print(ex.code) 95 | 96 | MergeAndDownload.execute() -------------------------------------------------------------------------------- /pdf-apis/GetPdfSessionDetails.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import SessionInfo, SessionMeta, SessionUserInfo, \ 7 | InvalidConfigurationException, Authentication, EditPdfParameters 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | class GetPdfSessionDetails: 12 | 13 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-pdfeditor-session-details.html 14 | @staticmethod 15 | def execute(): 16 | GetPdfSessionDetails.init_sdk() 17 | editDocumentParams = EditPdfParameters() 18 | 19 | # Either use url as document source or attach the document in request body use below methods 20 | editDocumentParams.set_url('https://demo.office-integrator.com/zdocs/BusinessIntelligence.pdf') 21 | 22 | v1Operations = V1Operations() 23 | response = v1Operations.edit_pdf(editDocumentParams) 24 | 25 | if response is not None: 26 | print('Status Code: ' + str(response.get_status_code())) 27 | responseObject = response.get_object() 28 | 29 | if responseObject is not None: 30 | if isinstance(responseObject, CreateDocumentResponse): 31 | sessionId = str(responseObject.get_session_id()) 32 | print('Created Document Session ID : ' + sessionId) 33 | 34 | sessionInfoResponse = v1Operations.get_session(sessionId) 35 | 36 | if sessionInfoResponse is not None: 37 | print('Status Code: ' + str(sessionInfoResponse.get_status_code())) 38 | sessionInfoObj = sessionInfoResponse.get_object() 39 | 40 | if sessionInfoObj is not None: 41 | if isinstance(sessionInfoObj, SessionMeta): 42 | print('Session Status : ' + str(sessionInfoObj.get_status())) 43 | 44 | sessionInfo = sessionInfoObj.get_info() 45 | 46 | if isinstance(sessionInfo, SessionInfo): 47 | print('Session User ID : ' + str(sessionInfo.get_session_url())) 48 | 49 | sessionUserInfo = sessionInfoObj.get_user_info() 50 | 51 | if isinstance(sessionUserInfo, SessionUserInfo): 52 | print('Session User ID : ' + str(sessionUserInfo.get_user_id())) 53 | print('Session Display Name : ' + str(sessionUserInfo.get_display_name())) 54 | elif isinstance(sessionInfoObj, InvalidConfigurationException): 55 | print('Invalid configuration exception.') 56 | print('Error Code : ' + str(sessionInfoObj.get_code())) 57 | print("Error Message : " + str(sessionInfoObj.get_message())) 58 | if sessionInfoObj.get_parameter_name() is not None: 59 | print("Error Parameter Name : " + str(sessionInfoObj.get_parameter_name())) 60 | if sessionInfoObj.get_key_name() is not None: 61 | print("Error Key Name : " + str(sessionInfoObj.get_key_name())) 62 | else: 63 | print('Get Session Details Request Failed') 64 | elif isinstance(responseObject, InvalidConfigurationException): 65 | print('Invalid configuration exception.') 66 | print('Error Code : ' + str(responseObject.get_code())) 67 | print("Error Message : " + str(responseObject.get_message())) 68 | if responseObject.get_parameter_name() is not None: 69 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 70 | if responseObject.get_key_name() is not None: 71 | print("Error Key Name : " + str(responseObject.get_key_name())) 72 | else: 73 | print('Create PDF Document Session Request Failed') 74 | 75 | @staticmethod 76 | def init_sdk(): 77 | try: 78 | #Sdk application log configuration 79 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 80 | #Update this apikey with your own apikey signed up in office integrator service 81 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 82 | tokens = [ auth ] 83 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 84 | environment = DataCenter.Production("https://api.office-integrator.com") 85 | 86 | Initializer.initialize(environment, tokens,None, None, logger, None) 87 | except SDKException as ex: 88 | print(ex.code) 89 | 90 | GetPdfSessionDetails.execute() -------------------------------------------------------------------------------- /presentation-apis/GetSessionDetails.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import SessionInfo, SessionMeta, \ 7 | InvalidConfigurationException, CreatePresentationParameters, Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | class GetSessionDetails: 12 | 13 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-show-session-information.html 14 | @staticmethod 15 | def execute(): 16 | GetSessionDetails.init_sdk() 17 | createPresentationParams = CreatePresentationParameters() 18 | 19 | print('Creating a presentation to demonstrate get presentation session information api') 20 | v1Operations = V1Operations() 21 | response = v1Operations.create_presentation(createPresentationParams) 22 | 23 | if response is not None: 24 | print('Status Code: ' + str(response.get_status_code())) 25 | responseObject = response.get_object() 26 | 27 | if responseObject is not None: 28 | if isinstance(responseObject, CreateDocumentResponse): 29 | sessionId = str(responseObject.get_session_id()) 30 | print('Created presentation Session ID : ' + sessionId) 31 | 32 | sessionInfoResponse = v1Operations.get_presentation_session(sessionId) 33 | 34 | if sessionInfoResponse is not None: 35 | print('Status Code: ' + str(sessionInfoResponse.get_status_code())) 36 | sessionInfoObj = sessionInfoResponse.get_object() 37 | 38 | if sessionInfoObj is not None: 39 | if isinstance(sessionInfoObj, SessionMeta): 40 | print('Session Status : ' + str(sessionInfoObj.get_status())) 41 | 42 | sessionInfo = sessionInfoObj.get_info() 43 | 44 | if isinstance(sessionInfo, SessionInfo): 45 | print('Presentation ID : ' + str(sessionInfo.get_document_id())) 46 | print('Presentation Session Created Time : ' + str(sessionInfo.get_created_time())) 47 | print('Presentation Session Created Timestamp : ' + str(sessionInfo.get_created_time_ms())) 48 | print('Presentation Session Expiry Time : ' + str(sessionInfo.get_expires_on())) 49 | print('Presentation Session Expiry Timestamp : ' + str(sessionInfo.get_expires_on_ms())) 50 | elif isinstance(sessionInfoObj, InvalidConfigurationException): 51 | print('Invalid configuration exception.') 52 | print('Error Code : ' + str(sessionInfoObj.get_code())) 53 | print("Error Message : " + str(sessionInfoObj.get_message())) 54 | if sessionInfoObj.get_parameter_name() is not None: 55 | print("Error Parameter Name : " + str(sessionInfoObj.get_parameter_name())) 56 | if sessionInfoObj.get_key_name() is not None: 57 | print("Error Key Name : " + str(sessionInfoObj.get_key_name())) 58 | else: 59 | print('Get Session Details Request Failed') 60 | elif isinstance(responseObject, InvalidConfigurationException): 61 | print('Invalid configuration exception.') 62 | print('Error Code : ' + str(responseObject.get_code())) 63 | print("Error Message : " + str(responseObject.get_message())) 64 | if responseObject.get_parameter_name() is not None: 65 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 66 | if responseObject.get_key_name() is not None: 67 | print("Error Key Name : " + str(responseObject.get_key_name())) 68 | else: 69 | print('Create presentation Request Failed') 70 | 71 | @staticmethod 72 | def init_sdk(): 73 | try: 74 | #Sdk application log configuration 75 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 76 | #Update this apikey with your own apikey signed up in office integrator service 77 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 78 | tokens = [ auth ] 79 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 80 | environment = DataCenter.Production("https://api.office-integrator.com") 81 | 82 | Initializer.initialize(environment, tokens,None, None, logger, None) 83 | except SDKException as ex: 84 | print(ex.code) 85 | 86 | GetSessionDetails.execute() -------------------------------------------------------------------------------- /document-apis/GetDocumentDetails.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentMeta, InvalidConfigurationException, \ 7 | Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_parameters import CreateDocumentParameters 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 11 | 12 | class GetDocumentDetails: 13 | 14 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-document-details.html 15 | @staticmethod 16 | def execute(): 17 | GetDocumentDetails.init_sdk() 18 | createDocumentParams = CreateDocumentParameters() 19 | 20 | print('Creating a document to demonstrate get all document information api') 21 | v1Operations = V1Operations() 22 | response = v1Operations.create_document(createDocumentParams) 23 | 24 | if response is not None: 25 | print('Status Code: ' + str(response.get_status_code())) 26 | responseObject = response.get_object() 27 | 28 | if responseObject is not None: 29 | if isinstance(responseObject, CreateDocumentResponse): 30 | documentId = str(responseObject.get_document_id()) 31 | print('Created Document ID : ' + documentId) 32 | 33 | documentInfoResponse = v1Operations.get_document_info(documentId) 34 | 35 | if documentInfoResponse is not None: 36 | print('Status Code: ' + str(documentInfoResponse.get_status_code())) 37 | documentInfoObj = documentInfoResponse.get_object() 38 | 39 | if documentInfoObj is not None: 40 | if isinstance(documentInfoObj, DocumentMeta): 41 | print('Document ID : ' + str(documentInfoObj.get_document_id())) 42 | print('Document Name : ' + str(documentInfoObj.get_document_name())) 43 | print('Document Type : ' + str(documentInfoObj.get_document_type())) 44 | print('Document Collaborators Count : ' + str(documentInfoObj.get_collaborators_count())) 45 | print('Document Created Time : ' + str(documentInfoObj.get_created_time())) 46 | print('Document Created Timestamp : ' + str(documentInfoObj.get_created_time_ms())) 47 | print('Document Expiry Time : ' + str(documentInfoObj.get_expires_on())) 48 | print('Document Expiry Timestamp : ' + str(documentInfoObj.get_expires_on_ms())) 49 | elif isinstance(documentInfoObj, InvalidConfigurationException): 50 | print('Invalid configuration exception.') 51 | print('Error Code : ' + str(documentInfoObj.get_code())) 52 | print("Error Message : " + str(documentInfoObj.get_message())) 53 | if documentInfoObj.get_parameter_name() is not None: 54 | print("Error Parameter Name : " + str(documentInfoObj.get_parameter_name())) 55 | if documentInfoObj.get_key_name() is not None: 56 | print("Error Key Name : " + str(documentInfoObj.get_key_name())) 57 | else: 58 | print('Get Document Details API Request Failed') 59 | elif isinstance(responseObject, InvalidConfigurationException): 60 | print('Invalid configuration exception.') 61 | print('Error Code : ' + str(responseObject.get_code())) 62 | print("Error Message : " + str(responseObject.get_message())) 63 | if responseObject.get_parameter_name() is not None: 64 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 65 | if responseObject.get_key_name() is not None: 66 | print("Error Key Name : " + str(responseObject.get_key_name())) 67 | else: 68 | print('Create Document Request Failed') 69 | 70 | @staticmethod 71 | def init_sdk(): 72 | try: 73 | #Sdk application log configuration 74 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 75 | #Update this apikey with your own apikey signed up in office integrator service 76 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 77 | tokens = [ auth ] 78 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 79 | environment = DataCenter.Production("https://api.office-integrator.com") 80 | 81 | Initializer.initialize(environment, tokens,None, None, logger, None) 82 | except SDKException as ex: 83 | print(ex.code) 84 | 85 | GetDocumentDetails.execute() -------------------------------------------------------------------------------- /document-apis/MergeAndDeliver.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 7 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 8 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 9 | 10 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, \ 11 | MergeAndDeliverViaWebhookParameters, MailMergeWebhookSettings, MergeAndDeliverViaWebhookSuccessResponse, \ 12 | Authentication, MergeAndDeliverRecordsMeta 13 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 14 | 15 | class MergeAndDeliver: 16 | 17 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/merge-and-deliver-via-webhook.html 18 | @staticmethod 19 | def execute(): 20 | MergeAndDeliver.init_sdk() 21 | parameter = MergeAndDeliverViaWebhookParameters() 22 | 23 | # Either use url as document source or attach the document in request body use below methods 24 | parameter.set_file_url('https://demo.office-integrator.com/zdocs/OfferLetter.zdoc') 25 | 26 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 27 | # filePath = ROOT_DIR + "/sample_documents/OfferLetter.zdoc" 28 | # print('Source document file path : ' + filePath) 29 | # parameter.set_file_content(StreamWrapper(file_path=filePath)) 30 | 31 | parameter.set_merge_data_json_url('https://demo.office-integrator.com/data/candidates.json') 32 | # jsonFilePath = ROOT_DIR + "/sample_documents/candidates.json" 33 | # print('Data Source Json file to be path : ' + jsonFilePath) 34 | # parameter.set_merge_data_json_content(StreamWrapper(file_path=jsonFilePath)) 35 | 36 | # parameter.set_merge_data_csv_url('https://demo.office-integrator.com/data/csv_data_source.csv') 37 | # filePath = ROOT_DIR + "/sample_documents/csv_data_source.csv" 38 | # print('Source document file path : ' + filePath) 39 | # parameter.set_merge_data_csv_content(StreamWrapper(file_path=filePath)) 40 | 41 | parameter.set_merge_to('separatedoc') 42 | parameter.set_output_format('pdf') 43 | parameter.set_password('***') 44 | 45 | webhookSettings = MailMergeWebhookSettings() 46 | 47 | webhookSettings.set_invoke_url('https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157a25e63fc4dfd4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286') 48 | webhookSettings.set_invoke_period('oncomplete') 49 | 50 | parameter.set_webhook(webhookSettings) 51 | 52 | v1Operations = V1Operations() 53 | response = v1Operations.merge_and_deliver_via_webhook(parameter) 54 | 55 | if response is not None: 56 | print('Status Code: ' + str(response.get_status_code())) 57 | responseObject = response.get_object() 58 | 59 | if responseObject is not None: 60 | if isinstance(responseObject, MergeAndDeliverViaWebhookSuccessResponse): 61 | mergeReportUrl = responseObject.get_merge_report_data_url() 62 | mergeRecords = responseObject.get_records() 63 | 64 | print('\nMerge Report URL : ' + mergeReportUrl) 65 | 66 | if isinstance(mergeRecords, list): 67 | print('\n---- Total Merged Records Count : ' + str(len(mergeRecords)) + " ----") 68 | for record in mergeRecords: 69 | if isinstance(record, MergeAndDeliverRecordsMeta): 70 | print('Records : Name - ' + str(record.get_name()) + ' Email - ' + str(record.get_email()) + ' Status - ' + str(record.get_status()) + ' Download Link - ' + str(record.get_download_link()) ) 71 | elif isinstance(responseObject, InvalidConfigurationException): 72 | print('Invalid configuration exception.') 73 | print('Error Code : ' + str(responseObject.get_code())) 74 | print("Error Message : " + str(responseObject.get_message())) 75 | if responseObject.get_parameter_name() is not None: 76 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 77 | if responseObject.get_key_name() is not None: 78 | print("Error Key Name : " + str(responseObject.get_key_name())) 79 | else: 80 | print('Create Merge Fields Request Failed') 81 | 82 | @staticmethod 83 | def init_sdk(): 84 | try: 85 | #Sdk application log configuration 86 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 87 | #Update this apikey with your own apikey signed up in office integrator service 88 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 89 | tokens = [ auth ] 90 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 91 | environment = DataCenter.Production("https://api.office-integrator.com") 92 | 93 | Initializer.initialize(environment, tokens,None, None, logger, None) 94 | except SDKException as ex: 95 | print(ex.code) 96 | 97 | MergeAndDeliver.execute() -------------------------------------------------------------------------------- /pdf-apis/GetPdfDocumentDetails.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentMeta, InvalidConfigurationException, \ 7 | Authentication, EditPdfParameters 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | class GetPdfDocumentDetails: 12 | 13 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-pdfeditor-document-info.html 14 | @staticmethod 15 | def execute(): 16 | GetPdfDocumentDetails.init_sdk() 17 | editDocumentParams = EditPdfParameters() 18 | 19 | # Either use url as document source or attach the document in request body use below methods 20 | editDocumentParams.set_url('https://demo.office-integrator.com/zdocs/BusinessIntelligence.pdf') 21 | 22 | print('Creating a pdf document session to demonstrate get all document information api') 23 | v1Operations = V1Operations() 24 | response = v1Operations.edit_pdf(editDocumentParams) 25 | 26 | if response is not None: 27 | print('Status Code: ' + str(response.get_status_code())) 28 | responseObject = response.get_object() 29 | 30 | if responseObject is not None: 31 | if isinstance(responseObject, CreateDocumentResponse): 32 | documentId = str(responseObject.get_document_id()) 33 | print('Created Document ID : ' + documentId) 34 | 35 | documentInfoResponse = v1Operations.get_document_info(documentId) 36 | 37 | if documentInfoResponse is not None: 38 | print('Status Code: ' + str(documentInfoResponse.get_status_code())) 39 | documentInfoObj = documentInfoResponse.get_object() 40 | 41 | if documentInfoObj is not None: 42 | if isinstance(documentInfoObj, DocumentMeta): 43 | print('Pdf Document ID : ' + str(documentInfoObj.get_document_id())) 44 | print('Pdf Document Name : ' + str(documentInfoObj.get_document_name())) 45 | print('Pdf Document Type : ' + str(documentInfoObj.get_document_type())) 46 | print('Pdf Document Collaborators Count : ' + str(documentInfoObj.get_collaborators_count())) 47 | print('Pdf Document Created Time : ' + str(documentInfoObj.get_created_time())) 48 | print('Pdf Document Created Timestamp : ' + str(documentInfoObj.get_created_time_ms())) 49 | print('Pdf Document Expiry Time : ' + str(documentInfoObj.get_expires_on())) 50 | print('Pdf Document Expiry Timestamp : ' + str(documentInfoObj.get_expires_on_ms())) 51 | elif isinstance(documentInfoObj, InvalidConfigurationException): 52 | print('Invalid configuration exception.') 53 | print('Error Code : ' + str(documentInfoObj.get_code())) 54 | print("Error Message : " + str(documentInfoObj.get_message())) 55 | if documentInfoObj.get_parameter_name() is not None: 56 | print("Error Parameter Name : " + str(documentInfoObj.get_parameter_name())) 57 | if documentInfoObj.get_key_name() is not None: 58 | print("Error Key Name : " + str(documentInfoObj.get_key_name())) 59 | else: 60 | print('Get Document Details API Request Failed') 61 | elif isinstance(responseObject, InvalidConfigurationException): 62 | print('Invalid configuration exception.') 63 | print('Error Code : ' + str(responseObject.get_code())) 64 | print("Error Message : " + str(responseObject.get_message())) 65 | if responseObject.get_parameter_name() is not None: 66 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 67 | if responseObject.get_key_name() is not None: 68 | print("Error Key Name : " + str(responseObject.get_key_name())) 69 | else: 70 | print('Create Pdf Document Session Request Failed') 71 | 72 | @staticmethod 73 | def init_sdk(): 74 | try: 75 | #Sdk application log configuration 76 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 77 | #Update this apikey with your own apikey signed up in office integrator service 78 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 79 | tokens = [ auth ] 80 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 81 | environment = DataCenter.Production("https://api.office-integrator.com") 82 | 83 | Initializer.initialize(environment, tokens,None, None, logger, None) 84 | except SDKException as ex: 85 | print(ex.code) 86 | 87 | GetPdfDocumentDetails.execute() -------------------------------------------------------------------------------- /document-apis/GetSessionDetails.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import SessionInfo, SessionMeta, SessionUserInfo, \ 7 | InvalidConfigurationException, UserInfo, Authentication 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_parameters import CreateDocumentParameters 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 11 | 12 | class GetSessionDetails: 13 | 14 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-session-information.html 15 | @staticmethod 16 | def execute(): 17 | GetSessionDetails.init_sdk() 18 | createDocumentParams = CreateDocumentParameters() 19 | 20 | print('Creating a document to demonstrate get document session information api') 21 | 22 | # Optional Configuration - Add User meta in request to identify the user in document session 23 | userInfo = UserInfo() 24 | userInfo.set_user_id("1000") 25 | userInfo.set_display_name("User 1") 26 | 27 | createDocumentParams.set_user_info(userInfo) 28 | 29 | v1Operations = V1Operations() 30 | response = v1Operations.create_document(createDocumentParams) 31 | 32 | if response is not None: 33 | print('Status Code: ' + str(response.get_status_code())) 34 | responseObject = response.get_object() 35 | 36 | if responseObject is not None: 37 | if isinstance(responseObject, CreateDocumentResponse): 38 | sessionId = str(responseObject.get_session_id()) 39 | print('Created Document Session ID : ' + sessionId) 40 | 41 | sessionInfoResponse = v1Operations.get_session(sessionId) 42 | 43 | if sessionInfoResponse is not None: 44 | print('Status Code: ' + str(sessionInfoResponse.get_status_code())) 45 | sessionInfoObj = sessionInfoResponse.get_object() 46 | 47 | if sessionInfoObj is not None: 48 | if isinstance(sessionInfoObj, SessionMeta): 49 | print('Session Status : ' + str(sessionInfoObj.get_status())) 50 | 51 | sessionInfo = sessionInfoObj.get_info() 52 | 53 | if isinstance(sessionInfo, SessionInfo): 54 | print('Session User ID : ' + str(sessionInfo.get_session_url())) 55 | 56 | sessionUserInfo = sessionInfoObj.get_user_info() 57 | 58 | if isinstance(sessionUserInfo, SessionUserInfo): 59 | print('Session User ID : ' + str(sessionUserInfo.get_user_id())) 60 | print('Session Display Name : ' + str(sessionUserInfo.get_display_name())) 61 | elif isinstance(sessionInfoObj, InvalidConfigurationException): 62 | print('Invalid configuration exception.') 63 | print('Error Code : ' + str(sessionInfoObj.get_code())) 64 | print("Error Message : " + str(sessionInfoObj.get_message())) 65 | if sessionInfoObj.get_parameter_name() is not None: 66 | print("Error Parameter Name : " + str(sessionInfoObj.get_parameter_name())) 67 | if sessionInfoObj.get_key_name() is not None: 68 | print("Error Key Name : " + str(sessionInfoObj.get_key_name())) 69 | else: 70 | print('Get Session Details Request Failed') 71 | elif isinstance(responseObject, InvalidConfigurationException): 72 | print('Invalid configuration exception.') 73 | print('Error Code : ' + str(responseObject.get_code())) 74 | print("Error Message : " + str(responseObject.get_message())) 75 | if responseObject.get_parameter_name() is not None: 76 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 77 | if responseObject.get_key_name() is not None: 78 | print("Error Key Name : " + str(responseObject.get_key_name())) 79 | else: 80 | print('Create Document Request Failed') 81 | 82 | @staticmethod 83 | def init_sdk(): 84 | try: 85 | #Sdk application log configuration 86 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 87 | #Update this apikey with your own apikey signed up in office integrator service 88 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 89 | tokens = [ auth ] 90 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 91 | environment = DataCenter.Production("https://api.office-integrator.com") 92 | 93 | Initializer.initialize(environment, tokens,None, None, logger, None) 94 | except SDKException as ex: 95 | print(ex.code) 96 | 97 | GetSessionDetails.execute() -------------------------------------------------------------------------------- /presentation-apis/CreatePresentation.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentInfo, UserInfo, \ 9 | CallbackSettings, InvalidConfigurationException, CreatePresentationParameters, ZohoShowEditorSettings, \ 10 | Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 12 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 13 | 14 | class CreatePresentation: 15 | 16 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-show-create-presentation.html 17 | @staticmethod 18 | def execute(): 19 | CreatePresentation.init_sdk() 20 | createPresentationParams = CreatePresentationParameters() 21 | 22 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 23 | documentInfo = DocumentInfo() 24 | documentInfo.set_document_name("New Presentation") 25 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 26 | 27 | createPresentationParams.set_document_info(documentInfo) 28 | 29 | # Optional Configuration - Add User meta in request to identify the user in document session 30 | userInfo = UserInfo() 31 | userInfo.set_user_id("1000") 32 | userInfo.set_display_name("User 1") 33 | 34 | createPresentationParams.set_user_info(userInfo) 35 | 36 | # Optional Configuration - Add callback settings to configure. 37 | # how file needs to be received while saving the document 38 | callbackSettings = CallbackSettings() 39 | 40 | # Optional Configuration - configure additional parameters 41 | # which can be received along with document while save callback 42 | saveUrlParams = {} 43 | 44 | saveUrlParams['id'] = '123131' 45 | saveUrlParams['auth_token'] = '1234' 46 | # Following $<> values will be replaced by actual value in callback request 47 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-create-document.html#saveurl_params 48 | saveUrlParams['extension'] = '$format' 49 | saveUrlParams['document_name'] = '$filename' 50 | saveUrlParams['session_id'] = '$session_id' 51 | 52 | callbackSettings.set_save_url_params(saveUrlParams) 53 | 54 | # Optional Configuration - configure additional headers 55 | # which could be received in callback request headers while saving document 56 | saveUrlHeaders = {} 57 | 58 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 59 | saveUrlHeaders['client_id'] = '12313111' 60 | 61 | # callbackSettings.set_save_url_headers(saveUrlHeaders) 62 | 63 | callbackSettings.set_retries(1) 64 | callbackSettings.set_timeout(10000) 65 | callbackSettings.set_save_format("pptx") 66 | callbackSettings.set_http_method_type("post") 67 | callbackSettings.set_save_url( 68 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 69 | 70 | createPresentationParams.set_callback_settings(callbackSettings) 71 | 72 | # Optional Configuration 73 | editorSettings = ZohoShowEditorSettings() 74 | 75 | editorSettings.set_language("en") 76 | 77 | createPresentationParams.set_editor_settings(editorSettings) 78 | 79 | # Optional Configuration - Configure permission values for session 80 | # based of you application requirement 81 | permissions = {} 82 | 83 | permissions["document.export"] = True 84 | permissions["document.print"] = True 85 | permissions["document.edit"] = True 86 | 87 | createPresentationParams.set_permissions(permissions) 88 | 89 | v1Operations = V1Operations() 90 | response = v1Operations.create_presentation(createPresentationParams) 91 | 92 | if response is not None: 93 | print('Status Code: ' + str(response.get_status_code())) 94 | responseObject = response.get_object() 95 | 96 | if responseObject is not None: 97 | if isinstance(responseObject, CreateDocumentResponse): 98 | print('Presentation Id : ' + str(responseObject.get_document_id())) 99 | print('Presentation Session ID : ' + str(responseObject.get_session_id())) 100 | print('Presentation Session URL : ' + str(responseObject.get_document_url())) 101 | print('Presentation Session Delete URL : ' + str(responseObject.get_session_delete_url())) 102 | print('Presentation Delete URL : ' + str(responseObject.get_document_delete_url())) 103 | elif isinstance(responseObject, InvalidConfigurationException): 104 | print('Invalid configuration exception.') 105 | print('Error Code : ' + str(responseObject.get_code())) 106 | print("Error Message : " + str(responseObject.get_message())) 107 | if responseObject.get_parameter_name() is not None: 108 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 109 | if responseObject.get_key_name() is not None: 110 | print("Error Key Name : " + str(responseObject.get_key_name())) 111 | else: 112 | print('Presentation Creation Request Failed') 113 | 114 | @staticmethod 115 | def init_sdk(): 116 | try: 117 | #Sdk application log configuration 118 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 119 | #Update this apikey with your own apikey signed up in office integrator service 120 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 121 | tokens = [ auth ] 122 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 123 | environment = DataCenter.Production("https://api.office-integrator.com") 124 | 125 | Initializer.initialize(environment, tokens,None, None, logger, None) 126 | except SDKException as ex: 127 | print(ex.code) 128 | 129 | CreatePresentation.execute() -------------------------------------------------------------------------------- /spreadsheet-apis/CreateSpreadsheet.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, CreateSheetParameters, \ 9 | DocumentInfo, \ 10 | SheetUserSettings, SheetCallbackSettings, SheetUiOptions, SheetEditorSettings, CreateSheetResponse, Authentication 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | 14 | class CreateSpreadsheet: 15 | 16 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-create-spreadsheet.html 17 | @staticmethod 18 | def execute(): 19 | CreateSpreadsheet.init_sdk() 20 | createSheetParams = CreateSheetParameters() 21 | 22 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 23 | documentInfo = DocumentInfo() 24 | documentInfo.set_document_name("New Spreadsheet") 25 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 26 | 27 | createSheetParams.set_document_info(documentInfo) 28 | 29 | # Optional Configuration - Add User meta in request to identify the user in document session 30 | userInfo = SheetUserSettings() 31 | 32 | userInfo.set_display_name("User 1") 33 | 34 | createSheetParams.set_user_info(userInfo) 35 | 36 | # Optional Configuration - Add callback settings to configure. 37 | # how file needs to be received while saving the document 38 | callbackSettings = SheetCallbackSettings() 39 | 40 | # Optional Configuration - configure additional parameters 41 | # which can be received along with document while save callback 42 | saveUrlParams = {} 43 | 44 | saveUrlParams['id'] = '123131' 45 | saveUrlParams['auth_token'] = '1234' 46 | # Following $<> values will be replaced by actual value in callback request 47 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-create-spreadsheet.html#saveurl_params 48 | saveUrlParams['extension'] = '$format' 49 | saveUrlParams['document_name'] = '$filename' 50 | 51 | callbackSettings.set_save_url_params(saveUrlParams) 52 | 53 | # Optional Configuration - configure additional headers 54 | # which could be received in callback request headers while saving document 55 | saveUrlHeaders = {} 56 | 57 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 58 | saveUrlHeaders['client_id'] = '12313111' 59 | 60 | callbackSettings.set_save_url_headers(saveUrlHeaders) 61 | 62 | callbackSettings.set_save_format("xlsx") 63 | callbackSettings.set_save_url( 64 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 65 | 66 | createSheetParams.set_callback_settings(callbackSettings) 67 | 68 | # Optional Configuration 69 | sheetEditorSettings = SheetEditorSettings() 70 | 71 | sheetEditorSettings.set_language('en') 72 | sheetEditorSettings.set_country('US') 73 | 74 | createSheetParams.set_editor_settings(sheetEditorSettings) 75 | 76 | # Optional Configuration 77 | sheetUiOptions = SheetUiOptions() 78 | 79 | sheetUiOptions.set_save_button("show") 80 | 81 | createSheetParams.set_ui_options(sheetUiOptions) 82 | 83 | # Optional Configuration - Configure permission values for session 84 | # based of you application requirement 85 | permissions = {} 86 | 87 | permissions["document.export"] = True 88 | permissions["document.print"] = True 89 | permissions["document.edit"] = True 90 | 91 | createSheetParams.set_permissions(permissions) 92 | 93 | v1Operations = V1Operations() 94 | response = v1Operations.create_sheet(createSheetParams) 95 | 96 | if response is not None: 97 | print('Status Code: ' + str(response.get_status_code())) 98 | responseObject = response.get_object() 99 | 100 | if responseObject is not None: 101 | if isinstance(responseObject, CreateSheetResponse): 102 | print('Spreadsheet Id : ' + str(responseObject.get_document_id())) 103 | print('Spreadsheet Session ID : ' + str(responseObject.get_session_id())) 104 | print('Spreadsheet Session URL : ' + str(responseObject.get_document_url())) 105 | print('Spreadsheet Session Grid View URL : ' + str(responseObject.get_gridview_url())) 106 | print('Spreadsheet Session Delete URL : ' + str(responseObject.get_session_delete_url())) 107 | print('Spreadsheet Delete URL : ' + str(responseObject.get_document_delete_url())) 108 | elif isinstance(responseObject, InvalidConfigurationException): 109 | print('Invalid configuration exception.') 110 | print('Error Code : ' + str(responseObject.get_code())) 111 | print("Error Message : " + str(responseObject.get_message())) 112 | if responseObject.get_parameter_name() is not None: 113 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 114 | if responseObject.get_key_name() is not None: 115 | print("Error Key Name : " + str(responseObject.get_key_name())) 116 | else: 117 | print('Spreadsheet Creation Request Failed') 118 | 119 | @staticmethod 120 | def init_sdk(): 121 | try: 122 | #Sdk application log configuration 123 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 124 | #Update this apikey with your own apikey signed up in office integrator service 125 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 126 | tokens = [ auth ] 127 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 128 | environment = DataCenter.Production("https://api.office-integrator.com") 129 | 130 | Initializer.initialize(environment, tokens,None, None, logger, None) 131 | except SDKException as ex: 132 | print(ex.code) 133 | 134 | CreateSpreadsheet.execute() -------------------------------------------------------------------------------- /document-apis/GetAllSessions.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | 7 | from officeintegrator.src.com.zoho.officeintegrator.v1 import AllSessionsResponse, SessionInfo, \ 8 | SessionMeta, SessionUserInfo, InvalidConfigurationException, UserInfo, Authentication 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_parameters import CreateDocumentParameters 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 12 | 13 | class GetAllSessions: 14 | 15 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-get-document-sessions.html 16 | @staticmethod 17 | def execute(): 18 | GetAllSessions.init_sdk() 19 | createDocumentParams = CreateDocumentParameters() 20 | 21 | # Optional Configuration - Add User meta in request to identify the user in document session 22 | userInfo = UserInfo() 23 | userInfo.set_user_id("1000") 24 | userInfo.set_display_name("User 1") 25 | 26 | createDocumentParams.set_user_info(userInfo) 27 | 28 | print('Creating a document to demonstrate get all document session information api') 29 | v1Operations = V1Operations() 30 | response = v1Operations.create_document(createDocumentParams) 31 | 32 | if response is not None: 33 | print('Status Code: ' + str(response.get_status_code())) 34 | responseObject = response.get_object() 35 | 36 | if responseObject is not None: 37 | if isinstance(responseObject, CreateDocumentResponse): 38 | documentId = str(responseObject.get_document_id()) 39 | print('Document ID to be deleted : ' + documentId) 40 | 41 | allSessionResponse = v1Operations.get_all_sessions(documentId) 42 | 43 | if allSessionResponse is not None: 44 | print('Status Code: ' + str(allSessionResponse.get_status_code())) 45 | allSessionsResponseObj = allSessionResponse.get_object() 46 | 47 | if allSessionsResponseObj is not None: 48 | if isinstance(allSessionsResponseObj, AllSessionsResponse): 49 | print('Document ID : ' + str(allSessionsResponseObj.get_document_id())) 50 | print('Document Name : ' + str(allSessionsResponseObj.get_document_name())) 51 | print('Document Type : ' + str(allSessionsResponseObj.get_document_type())) 52 | print('Document Created Time : ' + str(allSessionsResponseObj.get_created_time())) 53 | print('Document Created Timestamp : ' + str(allSessionsResponseObj.get_created_time_ms())) 54 | print('Document Expiry Time : ' + str(allSessionsResponseObj.get_expires_on())) 55 | print('Document Expiry Timestamp : ' + str(allSessionsResponseObj.get_expires_on_ms())) 56 | 57 | sessions = allSessionsResponseObj.get_sessions() 58 | 59 | print('\n---- Document Session Details ----\n') 60 | 61 | for session in sessions: 62 | if isinstance(session, SessionMeta): 63 | print('Session Status : ' + str(session.get_status())) 64 | 65 | sessionInfo = session.get_info() 66 | 67 | if isinstance(sessionInfo, SessionInfo): 68 | print('Session User ID : ' + str(sessionInfo.get_session_url())) 69 | 70 | sessionUserInfo = session.get_user_info() 71 | 72 | if isinstance(sessionUserInfo, SessionUserInfo): 73 | print('Session User ID : ' + str(sessionUserInfo.get_user_id())) 74 | print('Session Display Name : ' + str(sessionUserInfo.get_display_name())) 75 | elif isinstance(allSessionsResponseObj, InvalidConfigurationException): 76 | print('Invalid configuration exception.') 77 | print('Error Code : ' + str(allSessionsResponseObj.get_code())) 78 | print("Error Message : " + str(allSessionsResponseObj.get_message())) 79 | if allSessionsResponseObj.get_parameter_name() is not None: 80 | print("Error Parameter Name : " + str(allSessionsResponseObj.get_parameter_name())) 81 | if allSessionsResponseObj.get_key_name() is not None: 82 | print("Error Key Name : " + str(allSessionsResponseObj.get_key_name())) 83 | else: 84 | print('Create All Session Details Request Failed') 85 | elif isinstance(responseObject, InvalidConfigurationException): 86 | print('Invalid configuration exception.') 87 | print('Error Code : ' + str(responseObject.get_code())) 88 | print("Error Message : " + str(responseObject.get_message())) 89 | if responseObject.get_parameter_name() is not None: 90 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 91 | if responseObject.get_key_name() is not None: 92 | print("Error Key Name : " + str(responseObject.get_key_name())) 93 | else: 94 | print('Create Document Request Failed') 95 | @staticmethod 96 | def init_sdk(): 97 | try: 98 | #Sdk application log configuration 99 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 100 | #Update this apikey with your own apikey signed up in office integrator service 101 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 102 | tokens = [ auth ] 103 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 104 | environment = DataCenter.Production("https://api.office-integrator.com") 105 | 106 | Initializer.initialize(environment, tokens,None, None, logger, None) 107 | except SDKException as ex: 108 | print(ex.code) 109 | 110 | GetAllSessions.execute() -------------------------------------------------------------------------------- /pdf-apis/EditPdf.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentInfo, UserInfo, CallbackSettings, \ 7 | InvalidConfigurationException, Authentication, EditPdfParameters, PdfEditorUiOptions, PdfEditorSettings 8 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 9 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 10 | 11 | import time 12 | import os 13 | 14 | class EditPdf: 15 | 16 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-pdfeditor-edit-document.html 17 | @staticmethod 18 | def execute(): 19 | EditPdf.init_sdk() 20 | editDocumentParams = EditPdfParameters() 21 | 22 | # Either use url as document source or attach the document in request body use below methods 23 | editDocumentParams.set_url('https://demo.office-integrator.com/zdocs/BusinessIntelligence.pdf') 24 | 25 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 26 | # filePath = ROOT_DIR + "/sample_documents/BusinessIntelligence.pdf" 27 | # print('Path for source file to be edited : ' + filePath) 28 | # editDocumentParams.set_document(StreamWrapper(file_path=filePath)) 29 | 30 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 31 | documentInfo = DocumentInfo() 32 | documentInfo.set_document_name("New Document") 33 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 34 | 35 | editDocumentParams.set_document_info(documentInfo) 36 | 37 | # Optional Configuration - Add User meta in request to identify the user in document session 38 | userInfo = UserInfo() 39 | userInfo.set_user_id("1000") 40 | userInfo.set_display_name("User 1") 41 | 42 | editDocumentParams.set_user_info(userInfo) 43 | 44 | # Optional Configuration - Add callback settings to configure. 45 | # how file needs to be received while saving the document 46 | callbackSettings = CallbackSettings() 47 | 48 | # Optional Configuration - configure additional parameters 49 | # which can be received along with document while save callback 50 | saveUrlParams = {} 51 | 52 | saveUrlParams['id'] = '123131' 53 | saveUrlParams['auth_token'] = '1234' 54 | # Following $<> values will be replaced by actual value in callback request 55 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-create-document.html#saveurl_params 56 | saveUrlParams['extension'] = '$format' 57 | saveUrlParams['document_name'] = '$filename' 58 | saveUrlParams['session_id'] = '$session_id' 59 | 60 | callbackSettings.set_save_url_params(saveUrlParams) 61 | 62 | # Optional Configuration - configure additional headers 63 | # which could be received in callback request headers while saving document 64 | saveUrlHeaders = {} 65 | 66 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 67 | saveUrlHeaders['client_id'] = '12313111' 68 | 69 | callbackSettings.set_save_url_headers(saveUrlHeaders) 70 | 71 | callbackSettings.set_retries(1) 72 | callbackSettings.set_timeout(10000) 73 | callbackSettings.set_save_format("pdf") 74 | callbackSettings.set_http_method_type("post") 75 | callbackSettings.set_save_url( 76 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 77 | 78 | editDocumentParams.set_callback_settings(callbackSettings) 79 | 80 | # Optional Configuration 81 | editorSettings = PdfEditorSettings() 82 | 83 | editorSettings.set_unit("in") 84 | editorSettings.set_language("en") 85 | 86 | editDocumentParams.set_editor_settings(editorSettings) 87 | 88 | # Optional Configuration 89 | uiOptions = PdfEditorUiOptions() 90 | 91 | uiOptions.set_file_menu("show") 92 | uiOptions.set_save_button("show") 93 | 94 | editDocumentParams.set_ui_options(uiOptions) 95 | 96 | v1Operations = V1Operations() 97 | response = v1Operations.edit_pdf(editDocumentParams) 98 | 99 | if response is not None: 100 | print('Status Code: ' + str(response.get_status_code())) 101 | responseObject = response.get_object() 102 | 103 | if responseObject is not None: 104 | if isinstance(responseObject, CreateDocumentResponse): 105 | print('Pdf Document Id : ' + str(responseObject.get_document_id())) 106 | print('Pdf Document Session ID : ' + str(responseObject.get_session_id())) 107 | print('Pdf Document Session URL : ' + str(responseObject.get_document_url())) 108 | print('Pdf Document Session Delete URL : ' + str(responseObject.get_session_delete_url())) 109 | print('Pdf Document Delete URL : ' + str(responseObject.get_document_delete_url())) 110 | elif isinstance(responseObject, InvalidConfigurationException): 111 | print('Invalid configuration exception.') 112 | print('Error Code : ' + str(responseObject.get_code())) 113 | print("Error Message : " + str(responseObject.get_message())) 114 | if responseObject.get_parameter_name() is not None: 115 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 116 | if responseObject.get_key_name() is not None: 117 | print("Error Key Name : " + str(responseObject.get_key_name())) 118 | else: 119 | print('Edit Pdf Document Request Failed') 120 | 121 | @staticmethod 122 | def init_sdk(): 123 | try: 124 | #Sdk application log configuration 125 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 126 | #Update this apikey with your own apikey signed up in office integrator service 127 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 128 | tokens = [ auth ] 129 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 130 | environment = DataCenter.Production("https://api.office-integrator.com") 131 | 132 | Initializer.initialize(environment, tokens,None, None, logger, None) 133 | except SDKException as ex: 134 | print(ex.code) 135 | 136 | 137 | EditPdf.execute() 138 | -------------------------------------------------------------------------------- /spreadsheet-apis/EditSpreadsheet.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 5 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 6 | from officeintegrator.src.com.zoho.api.authenticator import Auth 7 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 8 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 9 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 10 | from officeintegrator.src.com.zoho.officeintegrator.v1 import InvalidConfigurationException, CreateSheetParameters, \ 11 | DocumentInfo, \ 12 | SheetUserSettings, SheetCallbackSettings, SheetUiOptions, SheetEditorSettings, CreateSheetResponse, Authentication 13 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 14 | 15 | class EditSpreadsheet: 16 | 17 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-edit-spreadsheet-v1.html 18 | @staticmethod 19 | def execute(): 20 | EditSpreadsheet.init_sdk() 21 | editSheetParams = CreateSheetParameters() 22 | 23 | # Either use url as document source or attach the document in request body use below methods 24 | editSheetParams.set_url('https://demo.office-integrator.com/samples/sheet/Contact_List.xlsx') 25 | 26 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 27 | # filePath = ROOT_DIR + "/sample_documents/Contact_List.xlsx" 28 | # print('Path for source file to be edited : ' + filePath) 29 | # editSheetParams.set_document(StreamWrapper(file_path=filePath)) 30 | 31 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 32 | documentInfo = DocumentInfo() 33 | documentInfo.set_document_name("New Spreadsheet") 34 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 35 | 36 | editSheetParams.set_document_info(documentInfo) 37 | 38 | # Optional Configuration - Add User meta in request to identify the user in document session 39 | userInfo = SheetUserSettings() 40 | 41 | userInfo.set_display_name("User 1") 42 | 43 | editSheetParams.set_user_info(userInfo) 44 | 45 | # Optional Configuration - Add callback settings to configure. 46 | # how file needs to be received while saving the document 47 | callbackSettings = SheetCallbackSettings() 48 | 49 | # Optional Configuration - configure additional parameters 50 | # which can be received along with document while save callback 51 | saveUrlParams = {} 52 | 53 | saveUrlParams['id'] = '123131' 54 | saveUrlParams['auth_token'] = '1234' 55 | # Following $<> values will be replaced by actual value in callback request 56 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-sheet-create-spreadsheet.html#saveurl_params 57 | saveUrlParams['extension'] = '$format' 58 | saveUrlParams['document_name'] = '$filename' 59 | 60 | callbackSettings.set_save_url_params(saveUrlParams) 61 | 62 | # Optional Configuration - configure additional headers 63 | # which could be received in callback request headers while saving document 64 | saveUrlHeaders = {} 65 | 66 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 67 | saveUrlHeaders['client_id'] = '12313111' 68 | 69 | callbackSettings.set_save_url_headers(saveUrlHeaders) 70 | 71 | callbackSettings.set_save_format("xlsx") 72 | callbackSettings.set_save_url( 73 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 74 | 75 | editSheetParams.set_callback_settings(callbackSettings) 76 | 77 | # Optional Configuration 78 | sheetEditorSettings = SheetEditorSettings() 79 | 80 | sheetEditorSettings.set_language('en') 81 | sheetEditorSettings.set_country('US') 82 | 83 | editSheetParams.set_editor_settings(sheetEditorSettings) 84 | 85 | # Optional Configuration 86 | sheetUiOptions = SheetUiOptions() 87 | 88 | sheetUiOptions.set_save_button("show") 89 | 90 | editSheetParams.set_ui_options(sheetUiOptions) 91 | 92 | # Optional Configuration - Configure permission values for session 93 | # based of you application requirement 94 | permissions = {} 95 | 96 | permissions["document.export"] = True 97 | permissions["document.print"] = True 98 | permissions["document.edit"] = True 99 | 100 | editSheetParams.set_permissions(permissions) 101 | 102 | v1Operations = V1Operations() 103 | response = v1Operations.create_sheet(editSheetParams) 104 | 105 | if response is not None: 106 | print('Status Code: ' + str(response.get_status_code())) 107 | responseObject = response.get_object() 108 | 109 | if responseObject is not None: 110 | if isinstance(responseObject, CreateSheetResponse): 111 | print('Spreadsheet Id : ' + str(responseObject.get_document_id())) 112 | print('Spreadsheet Session ID : ' + str(responseObject.get_session_id())) 113 | print('Spreadsheet Session URL : ' + str(responseObject.get_document_url())) 114 | print('Spreadsheet Session Grid View URL : ' + str(responseObject.get_gridview_url())) 115 | print('Spreadsheet Session Delete URL : ' + str(responseObject.get_session_delete_url())) 116 | print('Spreadsheet Delete URL : ' + str(responseObject.get_document_delete_url())) 117 | elif isinstance(responseObject, InvalidConfigurationException): 118 | print('Invalid configuration exception.') 119 | print('Error Code : ' + str(responseObject.get_code())) 120 | print("Error Message : " + str(responseObject.get_message())) 121 | if responseObject.get_parameter_name() is not None: 122 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 123 | if responseObject.get_key_name() is not None: 124 | print("Error Key Name : " + str(responseObject.get_key_name())) 125 | else: 126 | print('Spreadsheet Creation Request Failed') 127 | 128 | @staticmethod 129 | def init_sdk(): 130 | try: 131 | #Sdk application log configuration 132 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 133 | #Update this apikey with your own apikey signed up in office integrator service 134 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 135 | tokens = [ auth ] 136 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 137 | environment = DataCenter.Production("https://api.office-integrator.com") 138 | 139 | Initializer.initialize(environment, tokens,None, None, logger, None) 140 | except SDKException as ex: 141 | print(ex.code) 142 | 143 | EditSpreadsheet.execute() -------------------------------------------------------------------------------- /presentation-apis/EditPresentation.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 5 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 6 | from officeintegrator.src.com.zoho.api.authenticator import Auth 7 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 8 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 9 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 10 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentInfo, UserInfo, \ 11 | CallbackSettings, InvalidConfigurationException, CreatePresentationParameters, ZohoShowEditorSettings, \ 12 | Authentication 13 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 14 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 15 | 16 | class EditPresentation: 17 | 18 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-show-edit-presentation-v1.html 19 | @staticmethod 20 | def execute(): 21 | EditPresentation.init_sdk() 22 | createPresentationParams = CreatePresentationParameters() 23 | 24 | # Either use url as document source or attach the document in request body use below methods 25 | # createPresentationParams.set_url('https://demo.office-integrator.com/samples/show/Zoho_Show.pptx') 26 | 27 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 28 | filePath = ROOT_DIR + "/sample_documents/Zoho_Show.pptx" 29 | print('Path for source file to be edited : ' + filePath) 30 | createPresentationParams.set_document(StreamWrapper(file_path=filePath)) 31 | 32 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 33 | documentInfo = DocumentInfo() 34 | documentInfo.set_document_name("New Presentation") 35 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 36 | 37 | createPresentationParams.set_document_info(documentInfo) 38 | 39 | # Optional Configuration - Add User meta in request to identify the user in document session 40 | userInfo = UserInfo() 41 | userInfo.set_user_id("1000") 42 | userInfo.set_display_name("User 1") 43 | 44 | createPresentationParams.set_user_info(userInfo) 45 | 46 | # Optional Configuration - Add callback settings to configure. 47 | # how file needs to be received while saving the document 48 | callbackSettings = CallbackSettings() 49 | 50 | # Optional Configuration - configure additional parameters 51 | # which can be received along with document while save callback 52 | saveUrlParams = {} 53 | 54 | saveUrlParams['id'] = '123131' 55 | saveUrlParams['auth_token'] = '1234' 56 | # Following $<> values will be replaced by actual value in callback request 57 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-create-document.html#saveurl_params 58 | saveUrlParams['extension'] = '$format' 59 | saveUrlParams['document_name'] = '$filename' 60 | saveUrlParams['session_id'] = '$session_id' 61 | 62 | callbackSettings.set_save_url_params(saveUrlParams) 63 | 64 | # Optional Configuration - configure additional headers 65 | # which could be received in callback request headers while saving document 66 | saveUrlHeaders = {} 67 | 68 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 69 | saveUrlHeaders['client_id'] = '12313111' 70 | 71 | # callbackSettings.set_save_url_headers(saveUrlHeaders) 72 | 73 | callbackSettings.set_retries(1) 74 | callbackSettings.set_timeout(10000) 75 | callbackSettings.set_save_format("pptx") 76 | callbackSettings.set_http_method_type("post") 77 | callbackSettings.set_save_url( 78 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 79 | 80 | createPresentationParams.set_callback_settings(callbackSettings) 81 | 82 | # Optional Configuration 83 | editorSettings = ZohoShowEditorSettings() 84 | 85 | editorSettings.set_language("en") 86 | 87 | createPresentationParams.set_editor_settings(editorSettings) 88 | 89 | # Optional Configuration - Configure permission values for session 90 | # based of you application requirement 91 | permissions = {} 92 | 93 | permissions["document.export"] = True 94 | permissions["document.print"] = True 95 | permissions["document.edit"] = True 96 | 97 | createPresentationParams.set_permissions(permissions) 98 | 99 | v1Operations = V1Operations() 100 | response = v1Operations.create_presentation(createPresentationParams) 101 | 102 | if response is not None: 103 | print('Status Code: ' + str(response.get_status_code())) 104 | responseObject = response.get_object() 105 | 106 | if responseObject is not None: 107 | if isinstance(responseObject, CreateDocumentResponse): 108 | print('Presentation Id : ' + str(responseObject.get_document_id())) 109 | print('Presentation Session ID : ' + str(responseObject.get_session_id())) 110 | print('Presentation Session URL : ' + str(responseObject.get_document_url())) 111 | print('Presentation Session Delete URL : ' + str(responseObject.get_session_delete_url())) 112 | print('Presentation Delete URL : ' + str(responseObject.get_document_delete_url())) 113 | elif isinstance(responseObject, InvalidConfigurationException): 114 | print('Invalid configuration exception.') 115 | print('Error Code : ' + str(responseObject.get_code())) 116 | print("Error Message : " + str(responseObject.get_message())) 117 | if responseObject.get_parameter_name() is not None: 118 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 119 | if responseObject.get_key_name() is not None: 120 | print("Error Key Name : " + str(responseObject.get_key_name())) 121 | else: 122 | print('Presentation Creation Request Failed') 123 | 124 | @staticmethod 125 | def init_sdk(): 126 | try: 127 | #Sdk application log configuration 128 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 129 | #Update this apikey with your own apikey signed up in office integrator service 130 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 131 | tokens = [ auth ] 132 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 133 | environment = DataCenter.Production("https://api.office-integrator.com") 134 | 135 | Initializer.initialize(environment, tokens,None, None, logger, None) 136 | except SDKException as ex: 137 | print(ex.code) 138 | 139 | EditPresentation.execute() -------------------------------------------------------------------------------- /document-apis/CreateDocument.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 4 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 5 | from officeintegrator.src.com.zoho.api.authenticator import Auth 6 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 7 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 8 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentInfo, UserInfo, Margin, DocumentDefaults, \ 9 | EditorSettings, UiOptions, CallbackSettings, InvalidConfigurationException, Authentication 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_parameters import CreateDocumentParameters 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 12 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 13 | 14 | 15 | class CreateDocument: 16 | 17 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-create-document.html 18 | @staticmethod 19 | def execute(): 20 | CreateDocument.init_sdk() 21 | createDocumentParams = CreateDocumentParameters() 22 | 23 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 24 | documentInfo = DocumentInfo() 25 | documentInfo.set_document_name("New Document") 26 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 27 | 28 | createDocumentParams.set_document_info(documentInfo) 29 | 30 | # Optional Configuration - Add User meta in request to identify the user in document session 31 | userInfo = UserInfo() 32 | userInfo.set_user_id("1000") 33 | userInfo.set_display_name("User 1") 34 | 35 | createDocumentParams.set_user_info(userInfo) 36 | 37 | # Optional Configuration - Add callback settings to configure. 38 | # how file needs to be received while saving the document 39 | callbackSettings = CallbackSettings() 40 | 41 | # Optional Configuration - configure additional parameters 42 | # which can be received along with document while save callback 43 | saveUrlParams = {} 44 | 45 | saveUrlParams['id'] = '123131' 46 | saveUrlParams['auth_token'] = '1234' 47 | # Following $<> values will be replaced by actual value in callback request 48 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-create-document.html#saveurl_params 49 | saveUrlParams['extension'] = '$format' 50 | saveUrlParams['document_name'] = '$filename' 51 | saveUrlParams['session_id'] = '$session_id' 52 | 53 | callbackSettings.set_save_url_params(saveUrlParams) 54 | 55 | # Optional Configuration - configure additional headers 56 | # which could be received in callback request headers while saving document 57 | saveUrlHeaders = {} 58 | 59 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 60 | saveUrlHeaders['client_id'] = '12313111' 61 | 62 | callbackSettings.set_save_url_headers(saveUrlHeaders) 63 | 64 | callbackSettings.set_retries(1) 65 | callbackSettings.set_timeout(10000) 66 | callbackSettings.set_save_format("zdoc") 67 | callbackSettings.set_http_method_type("post") 68 | callbackSettings.set_save_url( 69 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 70 | 71 | createDocumentParams.set_callback_settings(callbackSettings) 72 | 73 | # Optional Configuration - Set margin while creating document itself. 74 | # It's applicable only for new documents. 75 | margin = Margin() 76 | 77 | margin.set_top("1in") 78 | margin.set_bottom("1in") 79 | margin.set_left("1in") 80 | margin.set_right("1in") 81 | 82 | # Optional Configuration - Set default settings for document while creating document itself. 83 | # It's applicable only for new documents. 84 | documentDefaults = DocumentDefaults() 85 | 86 | documentDefaults.set_font_size(12) 87 | documentDefaults.set_paper_size("A4") 88 | documentDefaults.set_font_name("Arial") 89 | documentDefaults.set_track_changes("enabled") 90 | documentDefaults.set_orientation("landscape") 91 | 92 | documentDefaults.set_margin(margin) 93 | documentDefaults.set_language("ta") 94 | 95 | createDocumentParams.set_document_defaults(documentDefaults) 96 | 97 | # Optional Configuration 98 | editorSettings = EditorSettings() 99 | 100 | editorSettings.set_unit("in") 101 | editorSettings.set_language("en") 102 | editorSettings.set_view("pageview") 103 | 104 | createDocumentParams.set_editor_settings(editorSettings) 105 | 106 | # Optional Configuration 107 | uiOptions = UiOptions() 108 | 109 | uiOptions.set_dark_mode("show") 110 | uiOptions.set_file_menu("show") 111 | uiOptions.set_save_button("show") 112 | uiOptions.set_chat_panel("show") 113 | 114 | createDocumentParams.set_ui_options(uiOptions) 115 | 116 | # Optional Configuration - Configure permission values for session 117 | # based of you application requirement 118 | permissions = {} 119 | 120 | permissions["document.export"] = True 121 | permissions["document.print"] = True 122 | permissions["document.edit"] = True 123 | permissions["review.comment"] = True 124 | permissions["review.changes.resolve"] = True 125 | permissions["document.pausecollaboration"] = True 126 | permissions["document.fill"] = False 127 | 128 | createDocumentParams.set_permissions(permissions) 129 | 130 | v1Operations = V1Operations() 131 | response = v1Operations.create_document(createDocumentParams) 132 | 133 | if response is not None: 134 | print('Status Code: ' + str(response.get_status_code())) 135 | responseObject = response.get_object() 136 | 137 | if responseObject is not None: 138 | if isinstance(responseObject, CreateDocumentResponse): 139 | print('Document Id : ' + str(responseObject.get_document_id())) 140 | print('Document Session ID : ' + str(responseObject.get_session_id())) 141 | print('Document Session URL : ' + str(responseObject.get_document_url())) 142 | print('Document Session Delete URL : ' + str(responseObject.get_session_delete_url())) 143 | print('Document Delete URL : ' + str(responseObject.get_document_delete_url())) 144 | elif isinstance(responseObject, InvalidConfigurationException): 145 | print('Invalid configuration exception.') 146 | print('Error Code : ' + str(responseObject.get_code())) 147 | print("Error Message : " + str(responseObject.get_message())) 148 | if responseObject.get_parameter_name() is not None: 149 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 150 | if responseObject.get_key_name() is not None: 151 | print("Error Key Name : " + str(responseObject.get_key_name())) 152 | else: 153 | print('Document Creation Request Failed') 154 | 155 | @staticmethod 156 | def init_sdk(): 157 | try: 158 | #Sdk application log configuration 159 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 160 | #Update this apikey with your own apikey signed up in office integrator service 161 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 162 | tokens = [ auth ] 163 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 164 | environment = DataCenter.Production("https://api.office-integrator.com") 165 | 166 | Initializer.initialize(environment, tokens,None, None, logger, None) 167 | except SDKException as ex: 168 | print(ex.code) 169 | 170 | 171 | CreateDocument.execute() 172 | -------------------------------------------------------------------------------- /document-apis/EditDocument.py: -------------------------------------------------------------------------------- 1 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 2 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 3 | from officeintegrator.src.com.zoho.api.authenticator import Auth 4 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 5 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 6 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 7 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentInfo, UserInfo, CallbackSettings, \ 8 | DocumentDefaults, \ 9 | EditorSettings, UiOptions, InvalidConfigurationException, Authentication 10 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_parameters import CreateDocumentParameters 11 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 12 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 13 | 14 | import time 15 | import os 16 | 17 | class EditDocument: 18 | 19 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-edit-document.html 20 | @staticmethod 21 | def execute(): 22 | EditDocument.init_sdk() 23 | createDocumentParams = CreateDocumentParameters() 24 | 25 | # Either use url as document source or attach the document in request body use below methods 26 | createDocumentParams.set_url('https://demo.office-integrator.com/zdocs/Graphic-Design-Proposal.docx') 27 | 28 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 29 | # filePath = ROOT_DIR + "/sample_documents/Graphic-Design-Proposal.docx" 30 | # print('Path for source file to be edited : ' + filePath) 31 | # createDocumentParams.set_document(StreamWrapper(file_path=filePath)) 32 | 33 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 34 | documentInfo = DocumentInfo() 35 | documentInfo.set_document_name("New Document") 36 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 37 | 38 | createDocumentParams.set_document_info(documentInfo) 39 | 40 | # Optional Configuration - Add User meta in request to identify the user in document session 41 | userInfo = UserInfo() 42 | userInfo.set_user_id("1000") 43 | userInfo.set_display_name("User 1") 44 | 45 | createDocumentParams.set_user_info(userInfo) 46 | 47 | # Optional Configuration - Add callback settings to configure. 48 | # how file needs to be received while saving the document 49 | callbackSettings = CallbackSettings() 50 | 51 | # Optional Configuration - configure additional parameters 52 | # which can be received along with document while save callback 53 | saveUrlParams = {} 54 | 55 | saveUrlParams['id'] = '123131' 56 | saveUrlParams['auth_token'] = '1234' 57 | # Following $<> values will be replaced by actual value in callback request 58 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-create-document.html#saveurl_params 59 | saveUrlParams['extension'] = '$format' 60 | saveUrlParams['document_name'] = '$filename' 61 | saveUrlParams['session_id'] = '$session_id' 62 | 63 | callbackSettings.set_save_url_params(saveUrlParams) 64 | 65 | # Optional Configuration - configure additional headers 66 | # which could be received in callback request headers while saving document 67 | saveUrlHeaders = {} 68 | 69 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 70 | saveUrlHeaders['client_id'] = '12313111' 71 | 72 | callbackSettings.set_save_url_headers(saveUrlHeaders) 73 | 74 | callbackSettings.set_retries(1) 75 | callbackSettings.set_timeout(10000) 76 | callbackSettings.set_save_format("zdoc") 77 | callbackSettings.set_http_method_type("post") 78 | callbackSettings.set_save_url( 79 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 80 | 81 | createDocumentParams.set_callback_settings(callbackSettings) 82 | 83 | # Optional Configuration - Set default settings for document while creating document itself. 84 | # It's applicable only for new documents. 85 | documentDefaults = DocumentDefaults() 86 | 87 | documentDefaults.set_track_changes("enabled") 88 | documentDefaults.set_language("ta") 89 | 90 | createDocumentParams.set_document_defaults(documentDefaults) 91 | 92 | # Optional Configuration 93 | editorSettings = EditorSettings() 94 | 95 | editorSettings.set_unit("in") 96 | editorSettings.set_language("en") 97 | editorSettings.set_view("pageview") 98 | 99 | createDocumentParams.set_editor_settings(editorSettings) 100 | 101 | # Optional Configuration 102 | uiOptions = UiOptions() 103 | 104 | uiOptions.set_dark_mode("show") 105 | uiOptions.set_file_menu("show") 106 | uiOptions.set_save_button("show") 107 | uiOptions.set_chat_panel("show") 108 | 109 | createDocumentParams.set_ui_options(uiOptions) 110 | 111 | # Optional Configuration - Configure permission values for session 112 | # based of you application requirement 113 | permissions = {} 114 | 115 | permissions["document.export"] = True 116 | permissions["document.print"] = True 117 | permissions["document.edit"] = True 118 | permissions["review.comment"] = True 119 | permissions["review.changes.resolve"] = True 120 | permissions["document.pausecollaboration"] = True 121 | permissions["document.fill"] = False 122 | 123 | createDocumentParams.set_permissions(permissions) 124 | 125 | v1Operations = V1Operations() 126 | response = v1Operations.create_document(createDocumentParams) 127 | 128 | if response is not None: 129 | print('Status Code: ' + str(response.get_status_code())) 130 | responseObject = response.get_object() 131 | 132 | if responseObject is not None: 133 | if isinstance(responseObject, CreateDocumentResponse): 134 | print('Document Id : ' + str(responseObject.get_document_id())) 135 | print('Document Session ID : ' + str(responseObject.get_session_id())) 136 | print('Document Session URL : ' + str(responseObject.get_document_url())) 137 | print('Document Session Delete URL : ' + str(responseObject.get_session_delete_url())) 138 | print('Document Delete URL : ' + str(responseObject.get_document_delete_url())) 139 | elif isinstance(responseObject, InvalidConfigurationException): 140 | print('Invalid configuration exception.') 141 | print('Error Code : ' + str(responseObject.get_code())) 142 | print("Error Message : " + str(responseObject.get_message())) 143 | if responseObject.get_parameter_name() is not None: 144 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 145 | if responseObject.get_key_name() is not None: 146 | print("Error Key Name : " + str(responseObject.get_key_name())) 147 | else: 148 | print('Edit Document Request Failed') 149 | 150 | @staticmethod 151 | def init_sdk(): 152 | try: 153 | #Sdk application log configuration 154 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 155 | #Update this apikey with your own apikey signed up in office integrator service 156 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 157 | tokens = [ auth ] 158 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 159 | environment = DataCenter.Production("https://api.office-integrator.com") 160 | 161 | Initializer.initialize(environment, tokens,None, None, logger, None) 162 | except SDKException as ex: 163 | print(ex.code) 164 | 165 | 166 | EditDocument.execute() 167 | -------------------------------------------------------------------------------- /document-apis/CreateMergeTemplate.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | from officeintegrator.src.com.zoho.officeintegrator.exception.sdk_exception import SDKException 5 | from officeintegrator.src.com.zoho.officeintegrator.dc import DataCenter 6 | from officeintegrator.src.com.zoho.api.authenticator import Auth 7 | from officeintegrator.src.com.zoho.officeintegrator.logger import Logger 8 | from officeintegrator.src.com.zoho.officeintegrator import Initializer 9 | from officeintegrator.src.com.zoho.officeintegrator.util import StreamWrapper 10 | from officeintegrator.src.com.zoho.officeintegrator.v1 import DocumentInfo, UserInfo, Margin, DocumentDefaults, \ 11 | EditorSettings, \ 12 | CallbackSettings, MailMergeTemplateParameters, InvalidConfigurationException, Authentication 13 | from officeintegrator.src.com.zoho.officeintegrator.v1.create_document_response import CreateDocumentResponse 14 | from officeintegrator.src.com.zoho.officeintegrator.v1.v1_operations import V1Operations 15 | 16 | class CreateMergeTemplate: 17 | 18 | # Refer API documentation - https://www.zoho.com/officeintegrator/api/v1/create-template.html 19 | @staticmethod 20 | def execute(): 21 | CreateMergeTemplate.init_sdk() 22 | createTemplateParams = MailMergeTemplateParameters() 23 | 24 | # Either use url as document source or attach the document in request body use below methods 25 | createTemplateParams.set_url("https://demo.office-integrator.com/zdocs/Graphic-Design-Proposal.docx") 26 | createTemplateParams.set_merge_data_json_url("https://demo.office-integrator.com/data/candidates.json") 27 | 28 | # ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 29 | # filePath = ROOT_DIR + "/sample_documents/OfferLetter.zdoc" 30 | # print('Source document file path : ' + filePath) 31 | # createTemplateParams.set_document(StreamWrapper(file_path=filePath)) 32 | 33 | # jsonFilePath = ROOT_DIR + "/sample_documents/candidates.json" 34 | # print('Data Source Json file to be path : ' + filePath) 35 | # createTemplateParams.set_merge_data_json_content(StreamWrapper(file_path=jsonFilePath)) 36 | 37 | # Optional Configuration - Add document meta in request to identify the file in Zoho Server 38 | documentInfo = DocumentInfo() 39 | documentInfo.set_document_name("New Document") 40 | documentInfo.set_document_id((round(time.time() * 1000)).__str__()) 41 | 42 | createTemplateParams.set_document_info(documentInfo) 43 | 44 | # Optional Configuration - Add User meta in request to identify the user in document session 45 | userInfo = UserInfo() 46 | userInfo.set_user_id("1000") 47 | userInfo.set_display_name("User 1") 48 | 49 | createTemplateParams.set_user_info(userInfo) 50 | 51 | # Optional Configuration - Add callback settings to configure. 52 | # how file needs to be received while saving the document 53 | callbackSettings = CallbackSettings() 54 | 55 | # Optional Configuration - configure additional parameters 56 | # which can be received along with document while save callback 57 | saveUrlParams = {} 58 | 59 | saveUrlParams['id'] = '123131' 60 | saveUrlParams['auth_token'] = '1234' 61 | # Following $<> values will be replaced by actual value in callback request 62 | # To know more - https://www.zoho.com/officeintegrator/api/v1/zoho-writer-create-document.html#saveurl_params 63 | saveUrlParams['extension'] = '$format' 64 | saveUrlParams['document_name'] = '$filename' 65 | saveUrlParams['session_id'] = '$session_id' 66 | 67 | callbackSettings.set_save_url_params(saveUrlParams) 68 | 69 | # Optional Configuration - configure additional headers 70 | # which could be received in callback request headers while saving document 71 | saveUrlHeaders = {} 72 | 73 | saveUrlHeaders['access_token'] = '12dweds32r42wwds34' 74 | saveUrlHeaders['client_id'] = '12313111' 75 | 76 | callbackSettings.set_save_url_headers(saveUrlHeaders) 77 | 78 | callbackSettings.set_retries(1) 79 | callbackSettings.set_timeout(10000) 80 | callbackSettings.set_save_format("zdoc") 81 | callbackSettings.set_http_method_type("post") 82 | callbackSettings.set_save_url( 83 | "https://officeintegrator.zoho.com/v1/api/webhook/savecallback/601e12157123434d4e6e00cc3da2406df2b9a1d84a903c6cfccf92c8286") 84 | 85 | createTemplateParams.set_callback_settings(callbackSettings) 86 | 87 | # Optional Configuration - Set margin while creating document itself. 88 | # It's applicable only for new documents. 89 | margin = Margin() 90 | 91 | margin.set_top("1in") 92 | margin.set_bottom("1in") 93 | margin.set_left("1in") 94 | margin.set_right("1in") 95 | 96 | # Optional Configuration - Set default settings for document while creating document itself. 97 | # It's applicable only for new documents. 98 | documentDefaults = DocumentDefaults() 99 | 100 | documentDefaults.set_font_size(12) 101 | documentDefaults.set_paper_size("A4") 102 | documentDefaults.set_font_name("Arial") 103 | documentDefaults.set_track_changes("enabled") 104 | documentDefaults.set_orientation("landscape") 105 | 106 | documentDefaults.set_margin(margin) 107 | documentDefaults.set_language("ta") 108 | 109 | createTemplateParams.set_document_defaults(documentDefaults) 110 | 111 | # Optional Configuration 112 | editorSettings = EditorSettings() 113 | 114 | editorSettings.set_unit("in") 115 | editorSettings.set_language("en") 116 | editorSettings.set_view("pageview") 117 | 118 | createTemplateParams.set_editor_settings(editorSettings) 119 | 120 | # Optional Configuration - Configure permission values for session 121 | # based of you application requirement 122 | permissions = {} 123 | 124 | permissions["document.export"] = True 125 | permissions["document.print"] = True 126 | permissions["document.edit"] = True 127 | permissions["review.comment"] = True 128 | permissions["review.changes.resolve"] = True 129 | permissions["document.pausecollaboration"] = True 130 | permissions["document.fill"] = False 131 | 132 | createTemplateParams.set_permissions(permissions) 133 | 134 | v1Operations = V1Operations() 135 | response = v1Operations.create_mail_merge_template(createTemplateParams) 136 | 137 | if response is not None: 138 | print('Status Code: ' + str(response.get_status_code())) 139 | responseObject = response.get_object() 140 | 141 | if responseObject is not None: 142 | if isinstance(responseObject, CreateDocumentResponse): 143 | print('Document Id : ' + str(responseObject.get_document_id())) 144 | print('Document Session ID : ' + str(responseObject.get_session_id())) 145 | print('Document Session URL : ' + str(responseObject.get_document_url())) 146 | print('Document Session Delete URL : ' + str(responseObject.get_session_delete_url())) 147 | print('Document Delete URL : ' + str(responseObject.get_document_delete_url())) 148 | elif isinstance(responseObject, InvalidConfigurationException): 149 | print('Invalid configuration exception.') 150 | print('Error Code : ' + str(responseObject.get_code())) 151 | print("Error Message : " + str(responseObject.get_message())) 152 | if responseObject.get_parameter_name() is not None: 153 | print("Error Parameter Name : " + str(responseObject.get_parameter_name())) 154 | if responseObject.get_key_name() is not None: 155 | print("Error Key Name : " + str(responseObject.get_key_name())) 156 | else: 157 | print('Merge Template Creation Request Failed') 158 | 159 | @staticmethod 160 | def init_sdk(): 161 | try: 162 | #Sdk application log configuration 163 | logger = Logger.get_instance(Logger.Levels.INFO, "./logs.txt") 164 | #Update this apikey with your own apikey signed up in office integrator service 165 | auth = Auth.Builder().add_param("apikey", "2ae438cf864488657cc9754a27daa480").authentication_schema(Authentication.TokenFlow()).build() 166 | tokens = [ auth ] 167 | # Refer this help page for api end point domain details - https://www.zoho.com/officeintegrator/api/v1/getting-started.html 168 | environment = DataCenter.Production("https://api.office-integrator.com") 169 | 170 | Initializer.initialize(environment, tokens,None, None, logger, None) 171 | except SDKException as ex: 172 | print(ex.code) 173 | 174 | CreateMergeTemplate.execute() 175 | --------------------------------------------------------------------------------