Mr-Help commited on
Commit
2d98bc7
·
verified ·
1 Parent(s): f2b1f7d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +49 -42
main.py CHANGED
@@ -5,53 +5,60 @@ app = FastAPI()
5
 
6
  # Constants
7
  ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
8
- FOLDER_ID = "90182650380"
9
- TEMPLATE_ID = "t-901804880155" # No "t-" prefix
10
- TEAM_ID = "9018441024" # This is the ClickUp "Team ID" shown in the URL
11
 
12
- @app.post("/")
13
- async def create_list_from_template(request: Request):
14
- data = await request.json()
15
- list_name = data.get("listName")
16
- contractor_type = data.get("contractorType", "").lower()
17
 
18
- if not list_name:
19
- return {"error": "Missing 'listName' in request"}
20
- if not contractor_type:
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"
28
- }
29
- payload = {
30
- "name": list_name,
31
- "options": {
32
- "return_immediately": True
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:
55
  return {
56
- "message": f"Contractor type '{contractor_type}' is not handled. No action taken."
 
 
57
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Constants
7
  ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
8
+ TEAM_ID = "9018441024"
 
 
9
 
10
+ # Video Contractor Settings
11
+ VIDEO_FOLDER_ID = "90182650380"
12
+ VIDEO_TEMPLATE_ID = "t-901804880155"
 
 
13
 
14
+ # Image Contractor Settings
15
+ IMAGE_FOLDER_ID = "90182896356"
16
+ IMAGE_TEMPLATE_ID = "t-901805178757"
17
+
18
+ def create_list_from_template(folder_id, template_id, list_name):
19
+ url = f"https://api.clickup.com/api/v2/folder/{folder_id}/list_template/{template_id}"
20
+ headers = {
21
+ "Authorization": ACCESS_TOKEN,
22
+ "Content-Type": "application/json"
23
+ }
24
+ payload = {
25
+ "name": list_name,
26
+ "options": {
27
+ "return_immediately": True
 
 
28
  }
29
+ }
30
 
31
+ response = requests.post(url, headers=headers, json=payload)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ if response.status_code == 200:
34
+ result = response.json()
35
+ list_id = result.get("id")
36
+ list_url = f"https://app.clickup.com/{TEAM_ID}/v/li/{list_id}"
37
+ return {"message": "✅ List created successfully.", "list_url": list_url}
38
  else:
39
  return {
40
+ "message": " Failed to create list.",
41
+ "status_code": response.status_code,
42
+ "error": response.text
43
  }
44
+
45
+ @app.post("/video")
46
+ async def create_video_contractor_list(request: Request):
47
+ data = await request.json()
48
+ list_name = data.get("listName")
49
+
50
+ if not list_name:
51
+ return {"error": "Missing 'listName' in request"}
52
+
53
+ return create_list_from_template(VIDEO_FOLDER_ID, VIDEO_TEMPLATE_ID, list_name)
54
+
55
+
56
+ @app.post("/image")
57
+ async def create_image_contractor_list(request: Request):
58
+ data = await request.json()
59
+ list_name = data.get("listName")
60
+
61
+ if not list_name:
62
+ return {"error": "Missing 'listName' in request"}
63
+
64
+ return create_list_from_template(IMAGE_FOLDER_ID, IMAGE_TEMPLATE_ID, list_name)