You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ClickUp空间文件夹获取失败:401未授权问题求助

排查ClickUp API获取Space文件夹的401未授权问题

尝试通过ClickUp API获取指定Space下的所有文件夹,但返回401未授权错误,代码片段如下:

import requests

# Enter your ClickUp API token here
api_token = 'pk_xxxxxxxxxxx'

# Space ID for the desired space
space_id = '1234567'

# API endpoint for retrieving folders in a space
folders_url = f'https://api.clickup.com/api/v2/space/{space_id}/folder'

# Headers with authorization
headers = {
    'Authorization': api_token,
    'Content-Type': 'application/json'
}

def list_all_folders():
    try:
        # Send GET request to retrieve folders in the space
        response = requests.get(folders_url, headers=headers)
        response.raise_for_status()  # Raise exception if request fails

        # Parse the JSON response
        folders_data = response.json()

        # Extract and print folder details
        for folder in folders_data['folders']:
            folder_id = folder['id']
            folder_name = folder['name']
            print(f"Folder ID: {folder_id}, Folder Name: {folder_name}")

    except requests.exceptions.HTTPError as err:
        print(f"Error: {err}")

# Call the function to list all folders in the space
list_all_folders()

运行时出现的错误:

Error: 401 Client Error: Unauthorized for url: https://api.clickup.com/api/v2/space/1234567/folder

以下是具体排查步骤:

  • 验证令牌有效性与权限:

    • 确认api_token是完整的pk_开头字符串,无多余空格或字符。
    • 登录ClickUp后台,进入设置 > 应用 > API令牌,检查该令牌是否拥有目标Space的space:read权限,且未被手动吊销。
  • 核对Space ID准确性:

    • 确认space_id完全正确,该Space需属于令牌对应的Workspace,不存在ID输入错误(如位数不足、字符错误)。
  • 检查请求头配置:

    • 确认请求头中Authorization字段拼写无误,无大小写错误(虽HTTP头不区分大小写,但建议严格匹配官方要求)。
  • 用工具直接测试API:

    • 使用curl发送请求排除代码逻辑问题:
      curl -H "Authorization: pk_xxxxxxxxxxx" https://api.clickup.com/api/v2/space/1234567/folder
      
    • 若curl请求同样返回401,说明问题出在令牌或权限;若curl成功,则检查代码中是否存在变量被意外修改的情况。

内容的提问来源于stack exchange,提问作者Rahul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 10:23:23