ClickUp Hierarchy Structure

Python code to get ClickUp space, workspace, and task details using ClickUp 2.0 API

ClickUp API to extract ClickUp space, workspace, and task details

Hi, I Hope you are doing well. Thank you so much for stopping by. It’s another day to learn something fruitful. To give you an idea of what we will be learning here. The guide continues my most recent guide, where we saw how to set up ClickUp API.  In this guide, we are going to learn to develop python code to use ClickUp API to get ClickUp workspace, spaces, lists, and tasks. But don’t worry I will add an example code demonstrating the use of the ClickUp access token.

Note: In this article, we are referring to ClickUp 2.0.

ClickUp Hierarchy Structure

Python code to get ClickUp workspace:

As you can see from the above the ClickUp hierarchy structure, first comes the workspace. 

This section below is the demo code demonstrating the use of the ClickUp API endpoint “team”. Workspace represents everyone and everything, I think that’s why the API endpoint is referred to as teams in ClickUp API. The endpoint also returns member’s details of a workspace.

#!/usr/local/bin/python3
#python3 code to get ClickUp Authorized Teams (Workspaces) and get members of workspace
#command to run the code -> python3 ./get_teams_workspace.py
 
import sys
import json
import requests
import pandas as pd
 
 
def get_workspace(clickup_api):
    try:
        url = "https://api.clickup.com/api/v2/team"
        headers = {"Authorization": clickup_api}
        r = requests.get(url = url, headers = headers)
        response_dict = json.loads(r.text)
 
        workspaces = response_dict["teams"]
       
        clickup_workspaces = pd.DataFrame()
        clickup_workspaces_list = []
        if workspaces:
            for workspace in workspaces:
                tmp_dict = {}
                workspace_id = workspace['id']
                workspace_name = workspace['name']
                tmp_dict["workspace_id"] = workspace_id
                tmp_dict["workspace_name"] = workspace_name
               
                #print("\n workspace name : %s | workspace id : %s "% (workspace_name, workspace_id))
 
                members = workspace['members']
                for member in members:
                    print("\n",member)
 
                clickup_workspaces_list.append(tmp_dict)
 
            clickup_workspaces = pd.DataFrame.from_records(clickup_workspaces_list)    
 
        return clickup_workspaces
    except:
        print("\n get_workspace failed : ",sys.exc_info())
 
 
 
if __name__ == '__main__':
    try:
        print("\n ClickUp get workspace process starts")
 
        clickup_api = "Replace with API key"
 
        clickup_workspaces_df = get_workspace(clickup_api)
        print(clickup_workspaces_df)  
 
 
        print("\n ClickUp get workspace process Finished")
    except:
        print("\n ClickUp ClickUp get workspace process Failed : ", sys.exc_info())

Python code to get ClickUp Spaces by workspace Id:

Second, in the hierarchy of ClickUp is Spaces. Space can be used to represent different projects of your organization. In big organizations, it can also represent departments. For this, we will be using the “space” endpoint of ClickUp API.

#!/usr/local/bin/python3
#python3 code to get ClickUp Spaces in a Workspaces
#command to run the code -> python3 ./get_spaces.py
import sys
import json
import requests
import pandas as pd
 
 
def get_spaces(clickup_api, workspace_id):
    try:
        url = f"https://api.clickup.com/api/v2/team/{workspace_id}/space?archived=false"
        headers = {"Authorization": clickup_api}
        r = requests.get(url = url, headers = headers)
        response_dict = json.loads(r.text)
 
        spaces = response_dict["spaces"]
       
        clickup_spaces = pd.DataFrame()
        clickup_spaces_list = []
        if spaces:
            for space in spaces:
                tmp_dict = {}
                space_id = space['id']
                space_name = space['name']
                features = space['features']
                #print("\nspace name : %s | Space id : %s "% (space_name, space_id))
                tmp_dict["space_id"] = space_id
                tmp_dict["space_name"] = space_name
       
                clickup_spaces_list.append(tmp_dict)
 
        clickup_spaces = pd.DataFrame.from_records(clickup_spaces_list)
 
        return clickup_spaces
    except:
        print("\n get_spaces Failed : ",sys.exc_info())
 
 
 
if __name__ == '__main__':
    try:
        print("\n ClickUp get spaces process starts")
 
        clickup_api = "Replace with ClickUp API key"
        workspace_id = "Replace with workspace Id eg: 10xxxx73"
 
        spaces_df = get_spaces(clickup_api, workspace_id)
        print(spaces_df)
 
        print("\n ClickUp get spaces process Finished.")
    except:
        print("\n ClickUp get spaces process Failed : ", sys.exc_info())
 

Python code to get ClickUp Space by Space ID:

In the above code, you will get a list of all spaces belonging to provided workspace ID. The below code will give you in-depth details about specific spaces.

#!/usr/local/bin/python3
#python3 code to get ClickUp Space
#command to run the code -> python3 ./get_space.py
import sys
import json
import requests
import pandas as pd
 
 
def get_space(clickup_api, space_id):
    try:
        url = f"https://api.clickup.com/api/v2/space/{space_id}"
        headers = {"Authorization": clickup_api}
        r = requests.get(url = url, headers = headers)
        response_dict = json.loads(r.text)
       
        if response_dict:
            tmp_dict = {}
            space_id = response_dict['id']
            space_name = response_dict['name']
            print("\n space details : %s "% response_dict)
       
        return response_dict
    except:
        print("\n get_spaces Failed : ",sys.exc_info())
 
 
 
if __name__ == '__main__':
    try:
        print("\n ClickUp get spaces process starts")
 
        clickup_api = "Replace with ClickUp API key"
        space_id = "Replace with space Id eg: 20xxxxx81"
 
        space_details = get_space(clickup_api, space_id)
        print(space_details)
 
        print("\n ClickUp get spaces process Finished.")
    except:
        print("\n ClickUp get spaces process Failed : ", sys.exc_info())
 

Python code to get ClickUp space folders:

Next in the hierarchy of ClickUp is Folders. Spaces consist of folders, folders are used to better organize the list of tasks. For example, the year 2022 is the folder for all week or month-wise list of tasks. Even though the folder is handy, ClickUp has provided flexibility by making the folder optional. To extract all the folders from ClickUp given space ID, you can use the below code. The python code uses the folder endpoint of ClickUp API to extract folder details.

#!/usr/local/bin/python3
#python3 code to get ClickUp folders of specific space
#command to run the code -> python3 ./get_folders.py
 
import sys
from datetime import datetime
import json
import requests
import pandas as pd
 
 
def get_folders(clickup_api, space_id):
    try:
        url = f"https://api.clickup.com/api/v2/space/{space_id}/folder"#?archived=false"
        headers = {"Authorization": clickup_api}
        r = requests.get(url = url, headers = headers)
        response_dict = json.loads(r.text)
 
        folders = response_dict["folders"]
        clickup_space_folders = pd.DataFrame()
        clickup_space_folder_list = []
        for folder in folders:
            tmp_dict = {}
            folder_id = folder['id']
            folder_name = folder['name']
            tmp_dict["folder_id"] = folder_id
            tmp_dict["folder_name"] = folder_name
            tmp_dict["folder_list"] = folder['lists']
 
            print("\n folder name : %s | folder id : %s "% (folder_name, folder_id))
 
            # for member in members:
            #     print("\n",member)
            clickup_space_folder_list.append(tmp_dict)
       
        clickup_space_folder = pd.DataFrame.from_records(clickup_space_folder_list)
 
        return clickup_space_folder
    except:
        print("\n*** Function (get_task_member) Failed *** ",sys.exc_info())
 
 
if __name__ == '__main__':
    try:
        timestamp = datetime.strftime(datetime.now(),'%Y-%m-%d : %H:%M')
        print("Code Run DATE : ",timestamp,"\n")
        print("ClickUp Analytics process starts")
 
        clickup_api = "Replace with API Key"
        space_id = "Replace with space Id eg: 20XXXXX81"
 
        clickup_space_folders = get_folders(clickup_api,space_id)
        print(clickup_space_folders)
 
       
        print("\n ClickUp Analytics Process Finished.")
    except:
        print("\n*** ClickUp Analytics Process Failed *** ", sys.exc_info())
 

Python code to get ClickUp Lists from space or folder:

Next in the hierarchy of ClickUp is Lists. A list can be within a folder or space directly. The list is a container for all the tasks. The best explanation is given by ClickUp i.e you can use the list to organize work for a specific timeframe such as sprints, by geographic location, or as phases of complex projects. To extract all the Lists from ClickUp given folder ID, you can use the below code. The python code uses the list endpoint of ClickUp API to extract list details.

#!/usr/local/bin/python3
#python3 code to get ClickUp lists from space
#command to run the code -> python3 ./get_lists.py
 
import sys
import json
import requests
import pandas as pd
 
 
def get_lists(clickup_api, folder_id):
    try:
        url = f"https://api.clickup.com/api/v2/folder/{folder_id}/list"
        headers = {"Authorization": clickup_api}
        r = requests.get(url = url, headers = headers)
        response_dict = json.loads(r.text)
 
        lists = response_dict["lists"]
 
        clickup_space_lists = pd.DataFrame()
        space_list = []
        for list in lists:
            tmp_dict = {}
            list_id = list['id']
            list_name = list['name']
            tmp_dict["list_id"] = list_id
            tmp_dict["list_name"] = list_name
 
            #print("\n list name : %s | list id : %s "% (list_name, list_id))
 
            space_list.append(tmp_dict)
 
        clickup_space_lists = pd.DataFrame.from_records(space_list)
 
        return clickup_space_lists
    except:
        print("\n*** Function (get_task_member) Failed *** ",sys.exc_info())
 
 
if __name__ == '__main__':
    try:
        print(" ClickUp space lists process starts")
 
        clickup_api = "replace with ClickUp API key"
        folder_id = "108039864"
 
        clickup_space_lists = get_lists(clickup_api, folder_id)
        print(clickup_space_lists)
           
        print("\n ClickUp space lists process Finished.")
    except:
        print("\n ClickUp space lists process Failed : ", sys.exc_info())
 

Python code to get ClickUp tasks details:

Finally in the hierarchy of ClickUp is Tasks. Without the ClickUp task feature, you can’t really carry out good project management. As the name suggests, one creates a task with a description of requirements or steps to be carried out to complete a project (you can also think of it as a to-do list needed for the completion of the project). A task moves from an open to close state. ClickUp provides a lot of flexibility to create different stages through which tasks move based on their status.

To extract all the tasks from ClickUp if you have a list ID, you can use the below code. The python code uses the task endpoint of ClickUp API to extract task details.

#!/usr/local/bin/python3
#python3 code to get ClickUp task list and details
#command to run the code -> python3 ./get_tasks.py
 
import sys
import json
import requests
import pandas as pd
 
 
def get_tasks_details(clickup_api, list_id):
    try:
        url = "https://api.clickup.com/api/v2/list/%s/task?archived=false"%list_id
        headers = {"Authorization": clickup_api}
        r = requests.get(url = url, headers = headers)
        response_dict = json.loads(r.text)
        #print(response_dict)
 
        tasks = response_dict["tasks"]
 
        clickup_tasks = pd.DataFrame()
        task_list = []
        for task in tasks:
            tmp_dict = {}
            task_id = task['id']
            task_name = task['name']
            task_content = task['text_content']
 
            tmp_dict["task_name"] = task_name
            tmp_dict["task_id"] = task_id
            tmp_dict["task_content"] = task_content
 
            tmp_dict["date_created"] = task['date_created']
            tmp_dict["status"] = task['status']['status']
            tmp_dict["creator"] = task['creator']
            tmp_dict["assignees"] = task['assignees']
            tmp_dict["watchers"] = task['watchers']
 
            #print("\n task name : %s | task id : %s "% (task_name, task_id))
 
            task_list.append(tmp_dict)
 
        clickup_tasks = pd.DataFrame.from_records(task_list)
 
        return clickup_tasks
 
    except:
        print("\n get_tasks_details Failed : ",sys.exc_info())
 
 
if __name__ == '__main__':
    try:
        print(" ClickUp task list and details process starts")
 
        clickup_api = "Replace with ClickUp API key"
        list_id = "380964205"
 
        tasks_details_df = get_tasks_details(clickup_api, list_id)
        print(tasks_details_df)
 
 
        print("\n ClickUp task list and details process Finished.")
    except:
        print("\n ClickUp task list and details process Failed : ", sys.exc_info())
 

Congratulations! you now know python logic to retrieve the ClickUp workspace, spaces, lists, and tasks using the ClickUp API (ClickUp 2.0). Hope I was able to make the entire process of building python logic to extract the ClickUp all Hierarchy Structure using API more straightforward.

If you have any questions or comments feel free to reach me at.

Checkout out my other API Integration and Coding Solution Guide