Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -6,8 +6,7 @@ app = FastAPI()
|
|
| 6 |
# Constants
|
| 7 |
ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
|
| 8 |
FOLDER_ID = "90182650380"
|
| 9 |
-
TEMPLATE_ID = "t-901804880155" # Remove
|
| 10 |
-
TEAM_ID = "90182086710" # Also known as Workspace or Space ID
|
| 11 |
|
| 12 |
@app.post("/")
|
| 13 |
async def create_list_from_template(request: Request):
|
|
@@ -21,7 +20,8 @@ async def create_list_from_template(request: Request):
|
|
| 21 |
return {"error": "Missing 'contractorType' in request"}
|
| 22 |
|
| 23 |
if contractor_type == "video":
|
| 24 |
-
|
|
|
|
| 25 |
headers = {
|
| 26 |
"Authorization": ACCESS_TOKEN,
|
| 27 |
"Content-Type": "application/json"
|
|
@@ -33,22 +33,38 @@ async def create_list_from_template(request: Request):
|
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
if
|
| 39 |
-
result =
|
| 40 |
list_id = result.get("id")
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
else:
|
| 47 |
return {
|
| 48 |
"message": "❌ Failed to create list.",
|
| 49 |
-
"status_code":
|
| 50 |
-
"error":
|
| 51 |
}
|
|
|
|
| 52 |
else:
|
| 53 |
return {
|
| 54 |
"message": f"Contractor type '{contractor_type}' is not handled. No action taken."
|
|
|
|
| 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 |
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 |
}
|
| 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 |
list_id = result.get("id")
|
| 41 |
+
|
| 42 |
+
# Step 2: Fetch the list details
|
| 43 |
+
get_url = f"https://api.clickup.com/api/v2/list/{list_id}"
|
| 44 |
+
get_response = requests.get(get_url, headers=headers)
|
| 45 |
+
|
| 46 |
+
if get_response.status_code == 200:
|
| 47 |
+
list_data = get_response.json()
|
| 48 |
+
team_id = list_data.get("space", {}).get("id")
|
| 49 |
+
list_url = f"https://app.clickup.com/{team_id}/v/l/li/{list_id}"
|
| 50 |
+
return {
|
| 51 |
+
"message": "✅ Video contractor list created successfully.",
|
| 52 |
+
"list_url": list_url
|
| 53 |
+
}
|
| 54 |
+
else:
|
| 55 |
+
return {
|
| 56 |
+
"message": "⚠️ List created but failed to fetch list info.",
|
| 57 |
+
"list_id": list_id,
|
| 58 |
+
"status_code": get_response.status_code,
|
| 59 |
+
"error": get_response.text
|
| 60 |
+
}
|
| 61 |
else:
|
| 62 |
return {
|
| 63 |
"message": "❌ Failed to create list.",
|
| 64 |
+
"status_code": create_response.status_code,
|
| 65 |
+
"error": create_response.text
|
| 66 |
}
|
| 67 |
+
|
| 68 |
else:
|
| 69 |
return {
|
| 70 |
"message": f"Contractor type '{contractor_type}' is not handled. No action taken."
|