testes/app/routes/zammad.py

40 lines
1.6 KiB
Python

import requests
base_url = "http://zammad.itguys.com.br/api/v1"
zammad_token = "kT0IXO8aVhPoTLcMRNL290rqd9jbRhhM0zf8MgBo3n00NLChToSU6rOGnMgWA0M2"
def listar_tickets(domain):
try:
headers = {
"Authorization": f"Token token={zammad_token}",
"Content-Type": "application/json"
}
url = f"{base_url}/tickets?domain={domain}"
response = requests.get(url, headers=headers, timeout=10)
if response.status_code == 200:
tickets = response.json()
tickets_filtrados = [
{
"title": ticket.get("title"),
"type": ticket.get("type"),
"created_at": ticket.get("created_at"),
"close_at": ticket.get("close_at"),
"state_id": ticket.get("state_id"),
"pending_time": ticket.get("pending_time"),
"number": ticket.get("number"),
"organization_id": ticket.get("organization_id"),
"customer_id": ticket.get("customer_id"),
}
for ticket in tickets
]
return tickets_filtrados, 200
else:
return {"error": f"Erro ao buscar tickets: {response.status_code}", "details": response.text}, response.status_code
except requests.exceptions.RequestException as e:
return {"error": "Erro na requisição à API", "details": str(e)}, 500
except Exception as e:
return {"error": "Erro interno ao processar a solicitação", "details": str(e)}, 500