A library for the Freshdesk helpdesk system for Python 2.7 and 3.
Currently it only supports the following API features:
- Getting a Ticket and filtering ticket lists
- Getting a Contact/User/Customer
- Viewing timesheets
The easiest way to install is from PyPi inside a virtualenv:
-
Create the virtualenv (Python 3!) and activate it:
$ virtualenv -p python3 cool_app $ cd cool_app && source bin/activate
-
Install from PyPi:
$ pip install python-freshdesk
-
Optionally, run the test suite:
$ pip install nose $ nosetests
Please note the domain and API key are not real and the example will not work without changing these.
>>> from freshdesk.api import API
>>> a = API('company.freshdesk.com', 'q8dnkjaS554Aol21dmnas9d92')
The API
class provides access to all the methods exposed by the Freshdesk API.
The Ticket API is accessed by using the methods assigned to the a.tickets
instance. Tickets are loaded as instances of the freshdesk.models.Ticket
class, and can be iterated over:
>>> a.tickets.list_open_tickets()
[<Ticket 'New ticket'>, <Ticket 'Some tests should be created'>, <Ticket 'Library needs to be uploaded to PyPi'>]
>>> a.tickets.list_deleted_tickets()
[<Ticket 'This is a sample ticket'>]
To see which attributes were loaded for a ticket:
>>> ticket = a.tickets.get_ticket(4)
>>> repr(ticket)
"<Ticket 'I keep typing Freskdesk instead of Freshdesk!>"
>>> ticket._keys
set([u'status', u'source_name', u'ticket_type', u'updated_at', ...])
Attributes are automatically converted to native Python objects where appropriate:
>>> a.tickets.list_open_tickets()[0].created_at
datetime.datetime(2014, 12, 5, 14, 7, 44)
Or converted from indexes to their descriptions:
>>> ticket.priority
'medium'
>>> ticket.status
'closed'
>>> ticket.source
'phone'
Viewing comments on a ticket are as simple as looking at the Ticket.comments
list:
>>> ticket.comments
[<Comment for <Ticket 'Some tests should be created'>>]
>>> ticket.comments[0]
'We could use Travis CI'
The original comment (called "description" in Freshdesk) is available on the Ticket
instance:
>>> ticket.description
'nose is a good suite'
Freshdesk mixes up the naming of contacts and users, depending on whether they are an agent or not.
python-freshdesk
simply calls them all contacts and are represented as Contact
instances:
>>> repr(a.contacts.get_contact('1234'))
"<Contact 'Rachel'>"
You can view all timesheets:
>>> a.timesheets.get_all_timesheets()
[<Timesheet Entry 1>, <Timesheet Entry 2, ...]
Or filter by ticket number:
>>> a.timesheets.get_timesheet_by_ticket(4)
[<Timesheet Entry 7>]