Kayako 4.01.240的Python API包装

kayako的Python项目详细描述


用法:

设置API:

>>> from kayako import KayakoAPI,
>>> API_URL = 'http://example.com/api/index.php'
>>> API_KEY = 'abc3r4f-alskcv3-kvj4'
>>> SECRET_KEY = 'vkl239vLKMNvlik42fv9IsflkFJlkckfjs'
>>> api = KayakoAPI(API_URL, API_KEY, SECRET_KEY)

添加部门:

>>> from kayako import Department
>>>
>>> # The following is equivalent to: department = api.create(Department, title='Customer Support Department', type='public', module='tickets'); department.add()
>>> department = api.create(Department)
>>> department.title = 'Customer Support Department'
>>> department.type = 'public'
>>> department.module = 'tickets'
>>> department.add()
>>> department.id
84
>>>
>>> # Cool, we now have a ticket department.
>>> # Lets say we want to make it private now
>>>
>>> department.type = 'private'
>>> department.save()
>>>
>>> # Ok, great.  Lets delete this test object.
>>>
>>> department.delete()
>>> department.id
UnsetParameter()
>>>
>>> # We can re-add it if we want to...
>>>
>>> department.save()
>>> department.id
85
>>>
>>> # Lets see all of our Departments (yours will vary.)
>>> for dept in api.get_all(Department):
...     print dept
...
<Department (1): General/tickets>
<Department (2): Suggest A Store/tickets>
<Department (3): Report A Bug/tickets>
<Department (4): Sales/livechat>
<Department (5): Commissions/livechat>
<Department (6): Missing Order/livechat>
<Department (7): Suggest A Feature/tickets>
<Department (8): Other/livechat>
<Department (49): Offers/tickets>
<Department (85): Customer Support Department/tickets>
>>>
>>> # Lets see all of our ticket Departments
>>>
>>> for dept in api.filter(Department, module='tickets')
>>>    print dept
<Department (1): General/tickets>
<Department (2): Suggest A Store/tickets>
<Department (3): Report A Bug/tickets>
<Department (7): Suggest A Feature/tickets>
<Department (49): Offers/tickets>
<Department (85): Customer Support Department/tickets>
>>>
>>> # We will use this Department in the next example so lets wait to clean up the test data...
>>> #department.delete()

添加工作人员:

>>> from kayako import Staff, StaffGroup
>>>
>>> # You can set parameters in the create method.
>>> staff = api.create(Staff, firstname='John', lastname='Doe', email='foo@example.com', username='explodes', password='easypass332')
>>>
>>> # We need to add a Staff member to a staff group.
>>> # Lets get the first StaffGroup titled "Administrator"
>>>
>>> admin_group = api.first(StaffGroup, title="Administrator")
>>> staff.staffgroupid = admin_group.id
>>>
>>> # And save the new Staff
>>>
>>> staff.add()
>>>
>>> # We will use this Staff in the next example so lets wait to clean up the test data...
>>> #staff.delete()

添加用户:

>>> from kayako import User, UserGroup, FOREVER
>>>
>>> # What fields can we add to this User?
>>> User.__add_parameters__
['fullname', 'usergroupid', 'password', 'email', 'userorganizationid', 'salutation', 'designation', 'phone', 'isenabled', 'userrole', 'timezone', 'enabledst', 'slaplanid', 'slaplanexpiry', 'userexpiry', 'sendwelcomeemail']
>>>
>>> # Lets make a new User, but not send out a welcome email.
>>> # Lets add the User to the "Registered" user group.
>>> registered = api.first(UserGroup, title='Registered')
>>> user = api.create(User, fullname="Ang Gary", password="easypass332", email="bar@example.com", usergroupid=registered.id, sendwelcomeemail=False, phone='1-800-555-5555', userexpiry=FOREVER)
>>> user.add()
>>>
>>> # Its that easy.  We will use this user in the next example so lets wait to clean up the test data...
>>> # user.delete()

添加票和票注意:

>>> from kayako import TicketStatus, TicketPriority, TicketType, TicketNote, TicketAttachment
>>>
>>> # Lets add a "Bug" Ticket to any Ticket Department, with "Open" status and "High" priority for a user. Lets use the user and department from above.
>>>
>>> bug = api.first(TicketType, title="Bug")
>>> open = api.first(TicketStatus, title="Open")
>>> high = api.first(TicketPriority, title="High")
>>>
>>> ticket = api.create(Ticket, tickettypeid=bug.id, ticketstatusid=open.id, ticketpriorityid=high.id, departmentid=department.id, userid=user.id)
>>> ticket.subject = 'I found a bug and its making me very angry.'
>>> ticket.fullname = 'Ang Gary'
>>> ticket.email = 'bar@example.com'
>>> ticket.contents = 'I am an angry customer you need to make me happy.'
>>> ticket.add()
>>>
>>> # The ticket was added, lets let the customer know that everything will be fine.
>>>
>>> print 'Thanks, %s, your inquiry with reference number %s will be answered shortly.' % (ticket.fullname, ticket.displayid)
Thanks, Ang Gary, your inquiry with reference number TOJ-838-99722 will be answered shortly.'
>>>
>>> # Lets add a note to this Ticket, using the Staff member we created above.
>>>
>>> note = api.create(TicketNote, ticketid=ticket.id, contents='Customer was hostile. Will pursue anyway as this bug is serious.')
>>> note.staffid = staff.id # Alternatively, we could do: staff.fullname = 'John Doe'
>>> note.add()
>>>
>>> # Lets say the bug is fixed, we want to let the User know.
>>>
>>> post = api.create(TicketPost, ticketid=ticket.id, subject="We fixed it.", contents="We have a patch that will fix the bug.")
>>> post.add()
>>>
>>> # Now lets add an attachment to this TicketPost.
>>>
>>> with open('/var/patches/foo.diff', 'rb') as patch:
...    binary_data = patch.read()
>>>
>>> attachment = api.create(TicketAttachment, ticketid=ticket.id, ticketpostid=post.id, filename='foo.diff', filetype='application/octet-stream')
>>> attachment.set_contents(binary_data) # set_contents encodes data into base 64. get_contents decodes base64 contents into the original data.
>>> attachment.add()
>>>
>>> # Lets clean up finally.
>>> ticket.delete() # This deletes the attachment, post, and note.
>>> user.delete()
>>> staff.delete()
>>> department.delete()

api工厂方法:

api.create(Object, *args, **kwargs)

Create and return a new ^{tt2}$ of the type given passing in args and kwargs.

api.get_all(Object, *args, **kwargs)

Get all ``KayakoObjects`` of the given type.In most cases, all items are returned.

e.x.

>>> api.get_all(Department)
[<Department....>, ....]

Special Cases:

^{tt4}$
Return all ^{tt5}$ from userid ^{tt6}$ with up to ^{tt7}$ results (max 1000.)
^{tt8}$
Return all ^{tt9}$ filtered by the required argument ^{tt10}$ and by the optional keyword arguments.
^{tt11}$
Return all ^{tt12}$ for a ^{tt13}$ with the given ID.
^{tt14}$
Return all ^{tt15}$ for a ^{tt13}$ with the given ID.
^{tt17}$
Return all ^{tt18}$ for a ^{tt13}$ with the given ID. Returns a ^{tt20}$ of ^{tt18}$.
^{tt22}$
Returns only one object: ^{tt23}$ not a ^{tt20}$ of objects.

api.filter(Object, args=(),kwargs={}, **filter)

Gets all ^{tt26}$ matching a filter.

e.x.

>>> api.filter(Department, args=(2), module='tickets')
[<Department module='tickets'...>, <Department module='tickets'...>, ...]

api.first(Object, args=(),kwargs={}, **filter)

Returns the first ^{tt2}$ found matching a given filter.

e.x.

>>> api.filter(Department, args=(2), module='tickets')
<Department module='tickets'>

api.get(Object, *args)

Get a ``KayakoObject`` of the given type by ID.

e.x.

>>> api.get(User, 112359)
<User (112359)....>

Special Cases:

^{tt30}$
Return a ^{tt31}$ for a ^{tt13}$ with the given ^{tt13}$ ID and ^{tt31}$ ID. Getting a specific ^{tt31}$ gets a ^{tt31}$ with the actual attachment contents.
^{tt37}$
Return a ^{tt38}$ for a ticket with the given ^{tt13}$ ID and ^{tt38}$ ID.
^{tt41}$
Return a ^{tt42}$ for a ticket with the given ^{tt13}$ ID and ^{tt42}$ ID.

对象持久化方法

kayakoobject.add()
将实例添加到kayako。
kayakoobject.save()
^ {EM1}$将现有对象实例保存到Kayako。
kayakoobject.delete()
从Kayako中删除实例

这些方法可以引发异常:

Raises ^{tt48}$ if one of the following is true:
  • The action is not available for the object
  • A required object parameter is UnsetParameter or None (add/save)
  • The API URL cannot be reached
Raises ^{tt49}$ if one of the following is true:
  • There is an error with the request (not HTTP 200 Ok)
  • The XML is in an unexpected format indicating a possible Kayako version mismatch

misc api调用

api.ticket_search(query, ticketid=False, contents=False, author=False, email=False, creatoremail=False, fullname=False, notes=False, usergroup=False, userorganization=False, user=False, tags=False)
使用指定字段中的查询搜索票证

更改

1.1.5

  • Fix ^{tt51}$.
  • ^{tt52}$ includes ^{tt53}$.
  • ^{tt54}$ is not returned in any responses, so it is not always available, removed it from ^{tt55}$.

1.1.4

  • Requires Kayako 4.01.240, use 1.1.3 for Kayako 4.01.204
  • ^{tt42}$ now supports get and delete
  • Added ^{tt57}$, see Misc API Calls for details.
  • Refactored ticket module into ticket package. This could cause problems if things were not imported like ^{tt58}$
  • Added ^{tt23}$ object. Use ^{tt22}$ to retrieve.
  • Added ^{tt61}$ object. ^{tt62}$ or ^{tt63}$
  • Added ^{tt64}$

快速参考

ObjectGet AllGetAddSaveDelete
DepartmentYesYesYesYesYes
StaffYesYesYesYesYes
StaffGroupYesYesYesYesYes
Ticketdepartmentid, ticketstatusid= -1, ownerstaffid= -1, userid= -1YesYesYesYes
TicketAttachmentticketidticketid, attachmentidYesNoYes
TicketCustomFieldticketidNoNoNoNo
TicketCountYesNoNoNoNo
TicketNoteticketidYesYesNoYes
TicketPostticketidticketid, postidYesNoYes
TicketPriorityYesYesNoNoNo
TicketStatusYesYesNoNoNo
TicketTimeTrackticketidticketid, idYesNoYes
TicketTypeYesYesNoNoNo
Usermarker=1, maxitems=1000YesYesYesYes
UserGroupYesYesYesYesYes
UserOrganizationYesYesYesYesYes

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Spring、JPA和hibernate的java问题   如何将JMC(Java任务控制)连接到ubuntu中的远程JVM?   java如何将eventListener的结果存储为对象?   java在安卓中,点击一个按钮,我如何停止发送循环中发送的消息   java打开活动中的电子邮件   使用velocity模板打印JasperReports   java无法在自定义信息窗口上拨号   java如何在jsonb postgresql中查询并转换为谓词JPA   java更好地理解J2EE环境中的异常和日志记录   java打印多个文件   java无法使用API v2 Foreman 1.7.1创建主机   HTML单一提交类型按钮在java中不起作用   java调用静态方法的实例   ViewPage中替换片段的java问题   C++在java中创建数组(2D)而不初始化内部数组   java如何在NetBeans中同时更改变量名称的多个实例?   如何完成这个关于集合的java程序   java如何选择使用selenium从下拉菜单动态生成的元素?