pythonautomationzabbixotrsticket-system

How to solve pyotrs error : "Failed to access OTRS API. Check Username and Password! Session ID expired?! Does Ticket exist?"


I have created a ticket with title "Test ticket" and now I am trying to get the details of the created ticket using pyotrs with following code:

from pyotrs import Client, Ticket

URL = "http://u/r/l"
USERNAME = "user"
PASSWORD = "pass"
#TICKET_LINK = URL + "/otrs/index.pl?Action=AgentTicketZoom;TicketID="

# Creating session
client = Client(URL, USERNAME, PASSWORD)
client.session_create()

ticket_ids = client.ticket_search(Title=["Test ticket"])
my_ticket=client.ticket_get_by_id(ticket_ids)
print(ticket_ids)
print(my_ticket.field_get("TicketNumber"))

This gives the following error:

Traceback (most recent call last):
  File "./search_ticket.py", line 16, in <module>
    my_ticket=client.ticket_get_by_id(ticket_ids)
  File "/opt/lib/python3.6/site-packages/pyotrs/lib.py", line 1309, in ticket_get_by_id
    if not self._parse_and_validate_response(response):
  File "/opt/lib/python3.6/site-packages/pyotrs/lib.py", line 2191, in _parse_and_validate_response
    self.result_json["Error"]["ErrorMessage"]))
pyotrs.lib.APIError: Failed to access OTRS API. Check Username and Password! Session ID expired?! Does Ticket exist?
OTRS Error Code: TicketGet.AccessDenied
OTRS Error Message: TicketGet: User does not have access to the ticket!

I got a fix here. But I don't have much idea how to fix this as the mentioned requests.request() is not present in my version of ticket_get_by_id(), in my pyotrs(pyotrs version-0.12.2, otrs-6). Alternately, is there any other issue which may be causing this? I am new to APIs and any help will be appreciated.


Solution

  • I replicated your error. You use my_ticket=client.ticket_get_by_id(ticket_ids), where ticket_ids is an array and ticket_get_by_id needs an integer. use this instead:

    my_ticket=client.ticket_get_by_id(ticket_ids[0]) To get the first ticket.