Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
|
| 6 |
+
# Constants
|
| 7 |
+
ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
|
| 8 |
+
FOLDER_ID = "90182650380"
|
| 9 |
+
TEMPLATE_ID = "901804880155" # No "t-" prefix for API call
|
| 10 |
+
|
| 11 |
+
@app.post("/")
|
| 12 |
+
async def create_list_from_template(request: Request):
|
| 13 |
+
data = await request.json()
|
| 14 |
+
list_name = data.get("listName")
|
| 15 |
+
contractor_type = data.get("contractorType", "").lower()
|
| 16 |
+
|
| 17 |
+
if not list_name:
|
| 18 |
+
return {"error": "Missing 'listName' in request"}
|
| 19 |
+
if not contractor_type:
|
| 20 |
+
return {"error": "Missing 'contractorType' in request"}
|
| 21 |
+
|
| 22 |
+
if contractor_type == "video":
|
| 23 |
+
url = f"https://api.clickup.com/api/v2/folder/{FOLDER_ID}/list_template/{TEMPLATE_ID}"
|
| 24 |
+
headers = {
|
| 25 |
+
"Authorization": ACCESS_TOKEN,
|
| 26 |
+
"Content-Type": "application/json"
|
| 27 |
+
}
|
| 28 |
+
payload = {
|
| 29 |
+
"name": list_name,
|
| 30 |
+
"options": {
|
| 31 |
+
"return_immediately": True
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 36 |
+
|
| 37 |
+
if response.status_code == 200:
|
| 38 |
+
result = response.json()
|
| 39 |
+
return {
|
| 40 |
+
"message": "✅ Video contractor list created successfully.",
|
| 41 |
+
"list_id": result.get("id")
|
| 42 |
+
}
|
| 43 |
+
else:
|
| 44 |
+
return {
|
| 45 |
+
"message": "❌ Failed to create list.",
|
| 46 |
+
"status_code": response.status_code,
|
| 47 |
+
"error": response.text
|
| 48 |
+
}
|
| 49 |
+
else:
|
| 50 |
+
return {
|
| 51 |
+
"message": f"Contractor type '{contractor_type}' is not handled. No action taken."
|
| 52 |
+
}
|