Working with Tickets
Create, search, get, and update Znuny tickets with the Python SDK.
Working with tickets — Znuny
All ticket operations are async. Use async with ZnunyClient(...) or call await client.aclose() when finished.
Authentication
Every API call requires a prior login():
from znuny import BasicAuth
client.login(BasicAuth(user_login="agent1", password="secret"))
Get a ticket
ticket = await client.get_ticket(12345)
print(ticket.title, ticket.queue)
Update a ticket
from znuny import IdName, TicketUpdate
updated = await client.update_ticket(
TicketUpdate(
id=12345,
state=IdName(name="closed successful"),
)
)
Search tickets
from znuny import IdName, TicketSearch
ids = await client.search_tickets(
TicketSearch(
queues=[IdName(name="Raw")],
limit=50,
)
)
Search and fetch full tickets
search_and_get runs search, then loads each ticket concurrently:
tickets = await client.search_and_get(
TicketSearch(queues=[IdName(name="Raw")])
)
for t in tickets:
print(t.id, t.title)
Error handling
GenericInterface business errors raise ZnunyError with code and message. HTTP transport problems raise httpx exceptions.
from znuny import ZnunyError
try:
await client.get_ticket(999999)
except ZnunyError as e:
print(e.code, e.message)
Dynamic fields
Pass dynamic fields as dict[str, str] on ticket models. The client maps them to GenericInterface DynamicField payloads automatically — the same field names you configured in Znuny.
