fix: use service_desk API format in instruct (authtoken, Accept header, json=payload, html description)

This commit is contained in:
Денис Кривоченко
2026-07-29 00:48:02 +07:00
parent baeac6b1cc
commit 708684fdfe
+8 -8
View File
@@ -94,11 +94,11 @@ def get_ad_user_info(user_id: str) -> dict | None:
raw_mail = str(entry.mail) if 'mail' in entry else ""
# mail может быть "[]" (пустой LDAP объект), "" или "N/A" — фильтруем
mail = raw_mail if raw_mail and raw_mail not in ("[]", "N/A", "") else None
# Fallback: используем UPN если mail пустой, конвертируем @sibcem.ru → @tcs.sibcem.ru
# Fallback: используем UPN если mail пустой
if not mail:
raw_upn = str(entry.userPrincipalName) if 'userPrincipalName' in entry else ""
if raw_upn and raw_upn not in ("[]", "N/A", ""):
mail = raw_upn.replace("@sibcem.ru", "@tcs.sibcem.ru")
mail = raw_upn
city = str(entry.l) if 'l' in entry and entry.l.value else "Кемерово"
return {"cn": cn, "mail": mail, "city": city}
except Exception as e:
@@ -121,7 +121,7 @@ async def _send_sd_api_request(requester_email: str, subject: str, description:
group_id = None
try:
url_groups = f"{SD_URL.rstrip('/')}/api/v3/groups"
headers = {"TECHNICIAN_KEY": SD_TOKEN}
headers = {"authtoken": SD_TOKEN, "Accept": "application/vnd.manageengine.sdp.v3+json"}
async with httpx.AsyncClient(verify=False) as client:
resp = await client.get(url_groups, headers=headers, timeout=10.0)
if resp.status_code == 200:
@@ -138,7 +138,7 @@ async def _send_sd_api_request(requester_email: str, subject: str, description:
tech_id = None
try:
url_techs = f"{SD_URL.rstrip('/')}/api/v3/technicians"
headers = {"TECHNICIAN_KEY": SD_TOKEN}
headers = {"authtoken": SD_TOKEN, "Accept": "application/vnd.manageengine.sdp.v3+json"}
async with httpx.AsyncClient(verify=False) as client:
resp = await client.get(url_techs, headers=headers, timeout=10.0)
if resp.status_code == 200:
@@ -151,10 +151,11 @@ async def _send_sd_api_request(requester_email: str, subject: str, description:
except Exception as e:
logger.warning(f"Failed to fetch SD technicians: {e}")
html_desc = f"<p>{description.replace(chr(10), '<br>')}</p><br><hr><p style='color:#555;font-size:12px;'><i>Создано через TrueConf КЛЕВЕР</i></p>"
payload = {
"request": {
"subject": subject,
"description": description,
"description": html_desc,
"requester": requester_payload,
"udf_fields": {
"udf_pick_301": city
@@ -168,11 +169,10 @@ async def _send_sd_api_request(requester_email: str, subject: str, description:
payload["request"]["assigned_to"] = {"id": tech_id}
url = f"{SD_URL.rstrip('/')}/api/v3/requests"
headers = {"TECHNICIAN_KEY": SD_TOKEN}
data = {"input_data": json.dumps(payload)}
headers = {"authtoken": SD_TOKEN, "Accept": "application/vnd.manageengine.sdp.v3+json"}
async with httpx.AsyncClient(verify=False) as client:
response = await client.post(url, headers=headers, data=data, timeout=15.0)
response = await client.post(url, headers=headers, json=payload, timeout=15.0)
if response.status_code in (200, 201):
res_json = response.json()