GithubHelp home page GithubHelp logo

kilo59 / zenpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from facetoe/zenpy

0.0 3.0 0.0 2.28 MB

Python wrapper for the Zendesk API

License: GNU General Public License v3.0

Python 100.00%

zenpy's Introduction

Build Status

Zenpy

Zenpy is a Python wrapper for the Zendesk, Chat and HelpCentre APIs. The goal of the project is to make it possible to write clean, fast, Pythonic code when interacting with Zendesk progmatically. The wrapper tries to keep API calls to a minimum. Wherever it makes sense objects are cached, and attributes of objects that would trigger an API call are evaluated lazily.

Zenpy supports both Python2 and Python3.

Note: HelpCentre API support is in beta.

Please report bugs!

Quickstart

from zenpy import Zenpy
# Create a Zenpy instance
zenpy_client = Zenpy(**credentials)

# Create a new ticket
zenpy_client.tickets.create(Ticket(subject="Important", description="Thing"))

# Perform a simple search
for ticket in zenpy_client.search("PC LOAD LETTER", type='ticket', assignee="facetoe"):
    # No need to mess around with ids, linked objects can be accessed directly.
    print(ticket.requester)

New Features

Pagination

Added experimental support for pagination using Python slices. Currently has a few limitations:

  • Does not support negative values (no fancy slicing)
  • Always pulls the first 100 objects (sometimes one extra API call than necessary)
  • Does not currently support multiple accesses

Usage:

ticket_generator = zenpy_client.tickets()

# Arguments to slice are [start:stop:page_size], they are all optional
tickets = ticket_generator[3950:4000:50]
print(tickets)

# Normal Python slice semantics, the following examples do what you would expect
tickets = ticket_generator[200:]
tickets = ticket_generator[:200]
tickets = ticket_generator[::]

Incremental object updates

Previously when executing code such as:

ticket = zenpy_client.tickets(id=1)
ticket.status = 'pending'
zenpy_client.tickets.update(ticket)

Every object attribute was sent off to Zendesk. This led to subtle bugs and is inefficient. Now, only those objects that have been modified will be sent. You can see which attributes will be sent as follows:

print(zenpy_object.to_dict(serialize=True))

Examples

Creating a ticket with a different requester
from zenpy.lib.api_objects import Ticket, User

zenpy_client.tickets.create(
    Ticket(description='Some description',
           requester=User(name='bob', email='[email protected]'))
)
Commenting on a ticket
from zenpy.lib.api_objects import Comment

ticket = zenpy_client.tickets(id=some_ticket_id)
ticket.comment = Comment(body="Important private comment", public=False)
zenpy_client.tickets.update(ticket)
Appending tags to a ticket
from zenpy.lib.api_objects import Ticket

ticket = zenpy_client.tickets(id=some_ticket_id)
ticket.tags.extend(['onetag', 'twotag', 'threetag', 'four'])
zenpy_client.tickets.update(ticket)
Uploading an attachment
from zenpy.lib.api_objects import Comment

# Upload the file (or file-like object) to Zendesk and obtain an Upload instance
upload_instance = zenpy_client.attachments.upload('/tmp/awesome_file.txt')

ticket = zenpy_client.tickets(id=some_ticket_id)
ticket.comment = Comment(body='This comment has my file attached', uploads=[upload_instance.token])
zenpy_client.tickets.update(ticket)
Creating a ticket with a custom field set
from zenpy.lib.api_objects import CustomField, Ticket

ticket_audit = zenpy_client.tickets.create(Ticket(
    subject='Has custom field',
    description="Wow, such field",
    custom_fields=[CustomField(id=43528467, value=1337)]
))
Updating a custom field on a ticket
from zenpy.lib.api_objects import CustomField
ticket = zenpy_client.tickets(id=some_ticket_id)
ticket.custom_fields.append(CustomField(id=43528467, value=1337))
zenpy_client.tickets.update(ticket)
Applying a Macro to a ticket
# Execute the show_macro_effect() method which returns what the macro *would* do.
# The method accepts either Zenpy objects or ids. 
macro_result = zenpy_client.tickets.show_macro_effect(ticket_id_or_object, macro_id_or_object)

# Update the ticket to actually change the ticket. 
zenpy_client.tickets.update(macro_result.ticket)
Adding a photo to a user
user = zenpy_client.users(id=user_id)
user.remote_photo_url = 'http://domain/example_photo.jpg'
zenpy_client.users.update(user)

Documentation

Check out the documentation for more info.

Contributions

Contributions are very welcome. I've written an explanation of the core ideas of the wrapper in the Contributors Guide.

zenpy's People

Contributors

dym avatar facetoe avatar facetoe-work avatar flpstrri avatar georgel9 avatar jgillmanjr avatar jpulec avatar kapoorabhish avatar michaelcosby avatar nick13jaremek avatar nkilian avatar onyb avatar oxmane avatar shaakmiller avatar sheled avatar urishalit avatar wilbuick avatar wontonst avatar yuvalbar avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.