Mr-Help commited on
Commit
4b25914
·
verified ·
1 Parent(s): 8983a0d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -33
main.py CHANGED
@@ -6,7 +6,8 @@ app = FastAPI()
6
  # Constants
7
  ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
8
  FOLDER_ID = "90182650380"
9
- TEMPLATE_ID = "t-901804880155" # Remove "t-" prefix for API call
 
10
 
11
  @app.post("/")
12
  async def create_list_from_template(request: Request):
@@ -20,8 +21,7 @@ async def create_list_from_template(request: Request):
20
  return {"error": "Missing 'contractorType' in request"}
21
 
22
  if contractor_type == "video":
23
- # Step 1: Create the list from template
24
- create_url = f"https://api.clickup.com/api/v2/folder/{FOLDER_ID}/list_template/{TEMPLATE_ID}"
25
  headers = {
26
  "Authorization": ACCESS_TOKEN,
27
  "Content-Type": "application/json"
@@ -33,41 +33,22 @@ async def create_list_from_template(request: Request):
33
  }
34
  }
35
 
36
- create_response = requests.post(create_url, headers=headers, json=payload)
37
 
38
- if create_response.status_code == 200:
39
- result = create_response.json()
40
- print("Creation response")
41
- print(result)
42
-
43
  list_id = result.get("id")
44
-
45
- # Step 2: Fetch the list details
46
- get_url = f"https://api.clickup.com/api/v2/list/{list_id}?include_url=true"
47
- get_response = requests.get(get_url, headers=headers)
48
-
49
- if get_response.status_code == 200:
50
- list_data = get_response.json()
51
- print("Get response")
52
- print(list_data)
53
- list_url = list_data.get("url") # ✅ Use built-in full URL
54
- return {
55
- "message": "✅ Video contractor list created successfully.",
56
- "list_url": list_url
57
- }
58
-
59
- else:
60
- return {
61
- "message": "⚠️ List created but failed to fetch list info.",
62
- "list_id": list_id,
63
- "status_code": get_response.status_code,
64
- "error": get_response.text
65
- }
66
  else:
67
  return {
68
  "message": "❌ Failed to create list.",
69
- "status_code": create_response.status_code,
70
- "error": create_response.text
71
  }
72
 
73
  else:
 
6
  # Constants
7
  ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
8
  FOLDER_ID = "90182650380"
9
+ TEMPLATE_ID = "901804880155" # No "t-" prefix
10
+ TEAM_ID = "t-9018441024" # This is the ClickUp "Team ID" shown in the URL
11
 
12
  @app.post("/")
13
  async def create_list_from_template(request: Request):
 
21
  return {"error": "Missing 'contractorType' in request"}
22
 
23
  if contractor_type == "video":
24
+ url = f"https://api.clickup.com/api/v2/folder/{FOLDER_ID}/list_template/{TEMPLATE_ID}"
 
25
  headers = {
26
  "Authorization": ACCESS_TOKEN,
27
  "Content-Type": "application/json"
 
33
  }
34
  }
35
 
36
+ response = requests.post(url, headers=headers, json=payload)
37
 
38
+ if response.status_code == 200:
39
+ result = response.json()
 
 
 
40
  list_id = result.get("id")
41
+ # ✅ Use the correct ClickUp team ID and path format
42
+ list_url = f"https://app.clickup.com/{TEAM_ID}/v/li/{list_id}"
43
+ return {
44
+ "message": "✅ Video contractor list created successfully.",
45
+ "list_url": list_url
46
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  else:
48
  return {
49
  "message": "❌ Failed to create list.",
50
+ "status_code": response.status_code,
51
+ "error": response.text
52
  }
53
 
54
  else: