import configparser import logging from pprint import pprint from ActiveCollabAPI import AC_LOGIN_BASE_URL from ActiveCollabAPI.ACAuthenticator import ACAuthenticator from ActiveCollabAPI.ACClient import ACClient from ActiveCollabAPI.ACTokenAuthenticator import ACTokenAuthenticator # Enabling debugging at http.client level (requests->urllib3->http.client) # you will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA. # the only thing missing will be the response.body which is not logged. from http.client import HTTPConnection from ActiveCollabAPI.ActiveCollab import ActiveCollab HTTPConnection.debuglevel = 1 logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True def main(): config = configparser.ConfigParser() config.read('config.ini') username = config['LOGIN']['username'] password = config['LOGIN']['password'] account_name = config['LOGIN']['account_name'] # 1. you need to log in to get a session and a list of accounts ac = ActiveCollab(AC_LOGIN_BASE_URL) session = ac.login(username, password) account = ac.get_account(session) # default returning first account token = ac.get_token(account, session.user) # 2. you need to get a token for this account token = ACTokenAuthenticator(account, auth.user).issue_token_intent() # pprint(token) # 3. now you can query the API ac = ACClient(account, token) # check version res = ac.get_info() ac_version = res.json() pprint(ac_version) if ac_version['version'] != '7.4.337': raise Exception("Supporting only Version 7.4.337!") # get a list of all projects # res = ac.get_projects() # pprint(res.json()) # get task with sub-tasks # "https://app.activecollab.com/416910/projects/310/tasks/6260" # project_id = 310 # task_id = 6260 # task_res = ac.get_project_task(project_id, task_id) # pprint(task_res.json()) # task = task_res.json() # ac.delete_all_open_subtasks(task) # create a new subtask for the task without assignment # subtask = { # "task_id": task_id, # "project_id": project_id, # "assignee_id": "", # "body": "test qqq" # } # res = ac.create_subtask(subtask) # pprint(res.json()) # # bulk create subtasks # subtask_texts = [] # with open("sub-tasks.txt", "r", encoding="utf-8") as fh: # for line in fh: # subtask_texts.append(line.rstrip('\n')) # create # for text in subtask_texts: # subtask['body'] = text # ac.create_subtask(subtask) # delete # for text in subtask_texts: # subtask = ac.find_subtask_with_body(task, text) # if subtask is not None: # print(subtask) # ac.delete_subtask(subtask) # # unassign a single subtask # subtask_id = 12203 # subtask_res = ac.get_project_task_subtask(project_id, task_id, subtask_id) # # pprint(subtask_res.json()) # subtask = subtask_res.json()['single'] # res = ac.unassign_sub_task(subtask) # pprint(res.json()) # delete a subtask # subtask = { # "task_id": task_id, # "project_id": project_id, # "id": 13764 # } # res = ac.delete_subtask(subtask) # pprint(res.json()) res = ac.get_projects() if res.status_code == 200: pprint(res.json()) if __name__ == "__main__": main()