Search a specific Ticket - Phyton API search

Zammad Hosted Version 6.0.0.633d0f8a2.saas

Testet on:

Microsoft Edge for Business
Version 116.0.1938.62 (64bit)

Python3.6

Hi,
I am just starting with programming. After a few times of small success, I am reaching my limit to search for a specific ticket by ticket number.
Can anyone give me a clue as to what I need to do.

I tried several versions of this syntax but it will not work.
ticket = client.ticket.search(name=‘20230831330666’)

Sorry here the correct line and error message.

ticket = zammad.ticket.search(number=‘20230831330017’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Resource.search() got an unexpected keyword argument ‘number’

Hi @Blacki-66 ,
we have no python libary so if you want help from the community then you should provide more information what libaries you are using.

I will take a guess that you might use the libary of this guy:

GitHub - joeirimpan/zammad_py: Python API client for accessing zammad REST API

Then based on the documentation it looks like that you need to provide a string as a parameter:

https://github.com/joeirimpan/zammad_py/blob/master/docs/usage.rst

from zammad_py import ZammadAPI
client = ZammadAPI(url='<HOST>', username='<USERNAME>', password='<PASSWORD>')
client.ticket.search('Search Content')

so try this:

ticket = zammad.ticket.search('number: 20230831330017')

Our search engine is elastic search. So for specific syntax you need to check their documentation:

Query string query | Elasticsearch Guide [8.9] | Elastic

Hello Rolf,

I use Visual Studiao Code for my programming.
Followed the instuction in the Zammad Admin Guide and then the Rest API Phython Documentation I was able to bring it to work. On the documentation Site is say PYPI V3.0.0

I be sure that the liary run and I’m connected to Zammad. BEcause I did some more scripts with it. But I collect the Data always with the ‘all’ option like this. And it works fine. ZammadPage is my cpunter to get all companies.

companys = zammad.organization.all(page = ZammadPage)

I get all companies in Excel exchanged the User_ID’s to names blabla …, I was happy :wink:

But now I want to search a specific Ticket. Our sales want an output of the ticket to meet the customers and talk about. We have only the profesional Version of Zammad. So without reporting. Thats the reason I want to do this.

OK. At first thanks for your help.
But your line end in

{‘tickets’: , ‘tickets_count’: 0, ‘assets’: {}}

this seems a empty list. so there is some issue with the text in the brackets. I try different variants, here i take the ID (only a test, I don’t know it in real)

ticket = zammad.ticket.find(8030)
^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\Python311\Lib\site-packages\zammad_py\api.py”, line 238, in find
return self._raise_or_return_json(response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\Python311\Lib\site-packages\zammad_py\api.py”, line 201, in _raise_or_return_json
response.raise_for_status()
File “C:\Users\MichaelSchwarz\AppData\Roaming\Python\Python311\site-packages\requests\models.py”, line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://schullerco.zammad.com/api/v1/tickets/8030

Surprisingly the link work.

BR
Michael

Hi @Blacki-66 ,

I’m really the wrong person for this. I never coded in python, but I will give a try:

test.py

from pprint import pprint
from zammad_py import ZammadAPI

client = ZammadAPI(url='http://ubuntu-rs:3000/api/v1', username='admin@example.com', password='test')
search = client.ticket.search('number:53001')

pprint(vars(search))
ubuntu-rs@ubuntu-rs:/workspace/git_zammad/Python-ZammadTicketSearch$ pip install zammad_py
ubuntu-rs@ubuntu-rs:/workspace/git_zammad/Python-ZammadTicketSearch$ python3 test.py
{'_function_name': 'search',
 '_items': [{'article_count': 1,
             'article_ids': [1],
             'close_at': None,
             'close_diff_in_min': None,
             'close_escalation_at': None,
             'close_in_min': None,
             'create_article_sender': 'Customer',
             'create_article_sender_id': 2,
             'create_article_type': 'phone',
             'create_article_type_id': 5,
             'created_at': '2023-08-26T08:58:32.967Z',
             'created_by': 'nicole.braun@zammad.org',
             'created_by_id': 2,
             'customer': 'nicole.braun@zammad.org',
             'customer_id': 2,
             'escalation_at': None,
             'first_response_at': None,
             'first_response_diff_in_min': None,
             'first_response_escalation_at': None,
             'first_response_in_min': None,
             'group': 'Users',
             'group_id': 1,
             'id': 1,
             'last_close_at': None,
             'last_contact_agent_at': None,
             'last_contact_at': '2023-08-31T08:38:38.385Z',
             'last_contact_customer_at': '2023-08-31T08:38:38.385Z',
             'last_owner_update_at': None,
             'note': None,
             'number': '53001',
             'organization': 'Zammad Foundation',
             'organization_id': 1,
             'owner': '-',
             'owner_id': 1,
             'pending_time': None,
             'preferences': {},
             'preview': 'blub',
             'priority': '2 normal',
             'priority_id': 2,
             'state': 'new',
             'state_id': 1,
             'ticket_time_accounting': [],
             'ticket_time_accounting_ids': [],
             'time_unit': None,
             'title': 'Welcome to Zammad!',
             'type': None,
             'update_diff_in_min': None,
             'update_escalation_at': None,
             'update_in_min': None,
             'updated_at': '2023-08-31T09:36:36.619Z',
             'updated_by': 'nicole.braun@zammad.org',
             'updated_by_id': 2}],
 '_page': 1,
 '_params': {'filters': {'expand': 'true',
                         'page': 1,
                         'per_page': 10,
                         'query': 'number:53001'},
             'search_string': 'number:53001'},
 '_resource': <zammad_py.api.Ticket object at 0x7f9cb1710520>}

You can do the same search in the frontend to make sure the the ticket exists which you are searching for.

Hello Rolf,

Yes, I know the Python API is Third-Party.
I learned Python last year just for fun and was happy to see that there is a way to use it with Zammad.

Unfortunately it doesn’t work as you show.
Because there is alo no other Topic in the community about this, my suggestion is that either Python is not really used, or my installtion is not correct.

I will check this first. But this will be in three weeks (Vacation Time :-D)

BR
Michael

I will close this Topic. I found an alternative solution for my case.