Getting all Zimbra Task Through SOAP

For example you want to fetch all task list which has branch in it as this picture.tasks_tree

You can fetch them using soap call Search for filter recursively task folder from root dir (/) and GetFolder for fetch task detail, here’s the example script of using mentioned soap call.

__author__ = ('Imam Omar Mochtar', 'iomarmochtar@gmail.com')
from ozpy.mailbox import Mailbox
import sys
from pprint import pprint
import os
"""
Example of fetching Zimbra task and task list (recursively).
"""
class MyMailbox(Mailbox):
def get_task(self, folder):
"""
Fetch task detail using SearchRequest
https://files.zimbra.com/docs/soap_api/8.7.11/api-reference/zimbraMail/Search.html
"""
body = {
"sortBy":"taskDueAsc",
"tz":{"id":"Asia/Bangkok"},
"locale":{"_content":"en_US"},
"offset":0,
"limit":100,
"query":"in:\"{}\"".format(folder),
"types":"task",
"needExp":1
}
urn = "urn:zimbraMail"
return self.send("Search", body, urn)
def get_task_folders(self):
"""
Get list of task folder using GetFolderRequest
https://files.zimbra.com/docs/soap_api/8.7.11/api-reference/zimbraMail/GetFolder.html
"""
urn = "urn:zimbraMail"
body = {
'folder': {'path': '/'},
'view': 'task'
}
return self.send("GetFolder", body, urn)
mbx = MyMailbox(
username="omar@jabetto.lab",
password="kacangitem",
soapurl="https://192.168.113.75/service/soap",
)
def fetch(name, instance):
"""
Fetch task and sub-task recursively
"""
name = os.path.join(name, instance['name'])
# print out task folder path
print("{} {}".format("-"*10,name))
task_req = mbx.get_task(name)
# iterrate all task within task folder if any
if task_req.has_key('task'):
for task in task_req['task']:
print('* {} - progress: {} % - location: {}'.format(
task['name'],
task['percentComplete'],
task['loc']
))
# loop if there are subfolder
if instance.has_key("folder"):
for folder in instance['folder']:
fetch(name, folder)
response = mbx.get_task_folders()
# get parent of task folder
for parent_folder in response['folder'][0]['folder']:
fetch("", parent_folder)

Here’s the console output of the script.

console_out

Leave a comment