Skip to content

Commit 4b2c65b

Browse files
author
Max Gutman
committed
Zendesk Python API Wrapper v1.0.0
0 parents  commit 4b2c65b

10 files changed

+815
-0
lines changed

CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v1.00, 2011-04-01 -- Initial release.

LICENSE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
3+
Copyright (c) 2009 - 2010 Ryan McGrath
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.txt
2+
recursive-include examples *

README.txt

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Zendesk API Wrapper for Python
2+
=========================================================================================
3+
Python Zendesk is wrapper for the Zendesk API. This library provides an
4+
easy and flexible way for developers to communicate with their Zendesk
5+
account in their application.
6+
7+
8+
Requirements
9+
-----------------------------------------------------------------------------------------------------
10+
httplib2 is used for authentication and requests
11+
12+
(pip install | easy_install) httplib2
13+
14+
dict2xml is used to create XML documents that will be posted to
15+
Zendesk. This module is included with this distribution, but credit goes to
16+
Vojtech Rylko: https://github.com/vojtarylko/dict2xml
17+
18+
19+
Installation
20+
-----------------------------------------------------------------------------------------------------
21+
Zendesk Python Library is available on pypi, so installation should be fairly simple:
22+
23+
(pip install | easy_install) zendesk
24+
25+
26+
Example Use
27+
-----------------------------------------------------------------------------------------------------
28+
29+
################################################################
30+
## NEW CONNECTION CLIENT
31+
################################################################
32+
zendesk = Zendesk('https://yourcompany.zendesk.com', '[email protected]', 'passwd')
33+
34+
################################################################
35+
## TICKETS
36+
################################################################
37+
38+
# List
39+
zendesk.list_tickets(view_id=1) # Must have a view defined
40+
41+
# Create
42+
new_ticket = {
43+
'ticket': {
44+
'requester-name': 'Howard Schultz',
45+
'requester-email': '[email protected]',
46+
'subject':'My Starbucks coffee is cold!',
47+
'description': 'please reheat my coffee',
48+
'set-tags': 'coffee drinks',
49+
'ticket-field-entries': {
50+
'@type': 'array',
51+
'ticket-field-entry': [
52+
{'ticket-field-id': 1, 'value': 'venti'},
53+
{'ticket-field-id': 2, 'value': '$10'}
54+
]
55+
},
56+
}
57+
}
58+
post_data = Zendesk.dict2xml(new_ticket)
59+
ticket_url = zendesk.create_ticket(xml_data=post_data)
60+
ticket_id = get_id_from_url(ticket_url)
61+
62+
# Show
63+
zendesk.show_ticket(ticket_id=ticket_id)
64+
65+
# Delete
66+
zendesk.delete_ticket(ticket_id=ticket_id)
67+
68+
# More examples in `examples` folder!
69+
70+

examples/__init__.py

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import re
2+
from zendesk import Zendesk
3+
4+
def get_id_from_url(url):
5+
match = re.match(r".*/(?P<identifier>\d+)\.xml", url)
6+
if match and match.group('identifier'):
7+
return match.group('identifier')
8+
9+
10+
################################################################
11+
## NEW CONNECTION CLIENT
12+
################################################################
13+
zendesk = Zendesk('https://yourcompany.zendesk.com', '[email protected]', 'passwd')
14+
15+
################################################################
16+
## TICKETS
17+
################################################################
18+
19+
# List
20+
zendesk.list_tickets(view_id=1) # Must have a view defined
21+
22+
# Create
23+
new_ticket = {
24+
'ticket': {
25+
'requester-name': 'Howard Schultz',
26+
'requester-email': '[email protected]',
27+
'subject':'My Starbucks coffee is cold!',
28+
'description': 'please reheat my coffee',
29+
'set-tags': 'coffee drinks',
30+
'ticket-field-entries': {
31+
'@type': 'array',
32+
'ticket-field-entry': [
33+
{'ticket-field-id': 1, 'value': 'venti'},
34+
{'ticket-field-id': 2, 'value': '$10'}
35+
]
36+
},
37+
}
38+
}
39+
post_data = Zendesk.dict2xml(new_ticket)
40+
ticket_url = zendesk.create_ticket(xml_data=post_data)
41+
ticket_id = get_id_from_url(ticket_url)
42+
43+
# Show
44+
zendesk.show_ticket(ticket_id=ticket_id)
45+
46+
# Delete
47+
zendesk.delete_ticket(ticket_id=ticket_id)
48+
49+
50+
################################################################
51+
## ORGANIZATIONS
52+
################################################################
53+
54+
# List
55+
zendesk.list_organizations()
56+
57+
# Create
58+
new_org = {
59+
'organization': {
60+
'name': 'Starbucks Corp'
61+
}
62+
}
63+
post_data = Zendesk.dict2xml(new_org)
64+
org_url = zendesk.create_organization(xml_data=post_data)
65+
org_id = get_id_from_url(org_url)
66+
67+
# Show
68+
zendesk.show_organization(organization_id=org_id)
69+
70+
# Delete
71+
zendesk.delete_organization(organization_id=org_id)
72+
73+
74+
################################################################
75+
## USERS (AGENTS)
76+
################################################################
77+
78+
# List
79+
zendesk.list_users()
80+
81+
# Create
82+
new_user = {
83+
'user': {
84+
'name': 'Howard Schultz',
85+
'email': '[email protected]',
86+
'roles': 4,
87+
}
88+
}
89+
post_data = Zendesk.dict2xml(new_user)
90+
user_url = zendesk.create_user(xml_data=post_data)
91+
user_id = get_id_from_url(user_url)
92+
93+
# Show
94+
zendesk.show_user(group_id=user_id)
95+
96+
# Delete
97+
zendesk.delete_user(group_id=user_id)
98+
99+
100+
################################################################
101+
## GROUPS
102+
################################################################
103+
104+
# List
105+
zendesk.list_groups()
106+
107+
# Create
108+
new_group = {
109+
'group': {
110+
'name': 'Starbucks Group',
111+
'agents': {
112+
'@type': 'array',
113+
'agent': 123,
114+
}
115+
}
116+
}
117+
post_data = Zendesk.dict2xml(new_group)
118+
group_url = zendesk.create_group(xml_data=post_data)
119+
group_id = get_id_from_url(group_url)
120+
121+
# Show
122+
zendesk.show_group(group_id=group_id)
123+
124+
# Delete
125+
zendesk.delete_group(group_id=group_id)
126+
127+
128+
################################################################
129+
## TAGS
130+
################################################################
131+
132+
# List
133+
zendesk.list_tags()
134+
135+
# Show
136+
zendesk.list_assets(tag_id=123, asset_type='event') # event | entry
137+
138+
139+
################################################################
140+
## TICKET TYPES
141+
################################################################
142+
zendesk.list_ticket_fields()
143+
144+
145+
################################################################
146+
## SEARCH
147+
################################################################
148+
149+
# http://www.zendesk.com/api/search
150+
# make sure to url-encode the query
151+
results = zendesk.search(query='ticket+sort:desc', page=1)

setup.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/python
2+
3+
from distutils.core import setup
4+
5+
setup(
6+
# Basic package information.
7+
name = 'Zendesk',
8+
author = 'Max Gutman',
9+
version = '1.0.0',
10+
author_email = '[email protected]',
11+
packages = ['zendesk'],
12+
include_package_data = True,
13+
install_requires = ['httplib2'],
14+
license='LICENSE.txt',
15+
url = 'http://github.com/eventbrite/zendesk/tree/master',
16+
keywords = 'zendesk api helpdesk',
17+
description = 'Python API Wrapper for Zendesk',
18+
classifiers = [
19+
'Development Status :: 4 - Beta',
20+
'Intended Audience :: Developers',
21+
'License :: OSI Approved :: MIT License',
22+
'Topic :: Software Development :: Libraries :: Python Modules',
23+
'Topic :: Internet'
24+
],
25+
)
26+
27+

zendesk/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from zendesk import *
2+
from endpoints import *

0 commit comments

Comments
 (0)