Extracting the Name of Zendesk Custom Fields through APIs in Python
I'm trying to extract the custom field names created by me (who is also an admin in Zendesk) through API calls in Zendesk with Python but so far have only been successful in extracting the IDs of the custom fields. Is there anyway to extract the name of the custom fields so I know what to populate it with. here is my code ,
credentials = {'token': ' ', 'email':'', 'subdomain': ' '}
create_ticket = zenpy_client.tickets.create(
Ticket(subject='This field will contain a subject',
description='This field will contain description',
requester=User(name='testtest'), assignee_id=5883758502685, priority='normal'
)
)
ticket_id = create_ticket.__dict__['ticket'].id
custom_field_ticket = zenpy_client.tickets(id=ticket_id)
custom_fields = custom_field_ticket.__dict__['custom_fields'] # this provides a list of IDs as list of dictionaries
Can anyone please provide some insight ?
-
Hi Uwemoqode,
The tickets api only returns field ids. To get field titles, you need to query the ticket field endpoint and cross reference the results.
I choose to query it once, save it as hashable, and use it to provide field titles.
Append this snippet to your code (python 3.10+):
# Save ticket fields id and title in a dict
ticket_fields = {}
for ticket_field in zenpy_client.ticket_fields():
ticket_fields[ticket_field.id] = ticket_field.title
# add the title attribute to the previously generated dict of ticket custom fields
for custom_field in custom_fields:
custom_field['title'] = ticket_fields[custom_field['id']]
print(custom_fields) # [{'id': 123, 'value': 'bar', 'title': 'foo'}]Now you can see the id, value, and title.
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
1 Kommentare