zenpy


Namezenpy JSON
Version 2.0.56 PyPI version JSON
download
home_pagehttps://github.com/facetoe/zenpy
SummaryPython wrapper for the Zendesk API
upload_time2024-11-21 02:20:09
maintainerNone
docs_urlNone
authorFace Toe
requires_pythonNone
licenseGPLv3
keywords zendesk api wrapper
VCS
bugtrack_url
requirements cachetools requests pytz python-dateutil six
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build Status](https://travis-ci.org/facetoe/zenpy.svg?branch=master)](https://travis-ci.org/facetoe/zenpy)

# Zenpy

Zenpy is a Python wrapper for the Zendesk, Chat and HelpCentre APIs. The goal of the project is to make it easy 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.

Please report bugs!

* [Quickstart](#quickstart)
* [Examples](#examples)
  * Ticketing
    * [Creating a ticket with a different requester](#creating-a-ticket-with-a-different-requester)
    * [Commenting on a ticket](#commenting-on-a-ticket)
    * [Adding a HTML comment to a ticket](#adding-a-html-comment-to-a-ticket)
    * [Appending tags to a ticket](#appending-tags-to-a-ticket)
    * [Uploading an attachment](#uploading-an-attachment)
    * [Creating a ticket with a custom field set](#creating-a-ticket-with-a-custom-field-set)
    * [Updating a custom field on a ticket](#updating-a-custom-field-on-a-ticket)
    * [Applying a Macro to a ticket](#applying-a-macro-to-a-ticket)
  * Users
    * [Adding a photo to a user](#adding-a-photo-to-a-user)
  * Help center
    * [List all categories from help center](#List-all-categories-from-help-center)
    * [List all help center articles](#List-all-help-center-articles)
    * [List all help center articles in a section](#List-all-help-center-articles-in-a-section)
    * [Create new category in help center](#Create-new-category-in-help-center)
    * [Create new section in help center](#Create-new-section-in-help-center)
    * [Create new article in help center](#Create-new-article-in-help-center)
  * Other
    * [Working with webhooks](#Working-with-webhooks)
    * [Pagination](#Pagination)
* [Documentation](#documentation)
* [Contributions](#contributions)

## Quickstart

```python
from zenpy import Zenpy
from zenpy.lib.api_objects import Ticket
# 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.name)

    # All objects can be converted to a Python dict.
    print(ticket.to_dict())

    # Or to JSON.
    print(ticket.to_json())
```

## Examples

##### Searching open and pending tickets for a specific user and sort them by descending

```python
zenpy_client.search(type='ticket', status_less_than='closed', assignee='foo@mail.foo', sort_order='desc')
```

##### Searching only opened tickets

```python
zenpy_client.search(type='ticket', status='open')
```

##### Exporting all tickets matching the query

By default, Search API has a limit of 1000 results in total.
Search Export API allows exporting unlimited number of results, so if you'd like to export all results, 
use this method instead:

```python
for ticket in zenpy_client.search_export(type='ticket', status='open'):
    print(ticket)
```

Read more about these limitations:

[Search results limits](https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#results-limit)

[Search Export API release notes](https://support.zendesk.com/hc/en-us/articles/4408825120538-Support-API-Announcing-the-Export-Search-Results-endpoint-)

##### Creating a ticket with a different requester

```python
from zenpy.lib.api_objects import Ticket, User

zenpy_client.tickets.create(
    Ticket(description='Some description',
           requester=User(name='bob', email='bob@example.com'))
)
```

##### Commenting on a ticket

```python
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)
```

##### Adding a HTML comment to a ticket

```python
from zenpy.lib.api_objects import Ticket, Comment

zenpy_client.tickets.create(Ticket(
    subject='Html comment example',
    comment=Comment(body='The smoke is very colorful',
                    html_body='<h2>The smoke is <i>very</i> colourful</h2>'))
)
```

##### Appending tags to a ticket

```python
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

```python
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 comment attachment and then redacting it

```python
# Upload the attachment
upload_instance = zenpy_client.attachments.upload('/tmp/awesome_file.txt')
comment = Comment(body='Some comment')
# Set the comment attachment affinity to this token.
comment.uploads = upload_instance.token

# Create the ticket, with that comment with that attachment affinity.  Can just as easily be a new comment on existing ticket.
ticket = Ticket(subject='example ticket', comment=comment)
ticket_audit = zenpy_client.tickets.create(ticket)
ticket = ticket_audit.ticket

# Get the last comment we just uploaded on that ticket.
the_commentresult = zenpy_client.tickets.comments(ticket)

# Redact the comment now that we just associated it with an attachment.
the_comment = the_commentresult.values[0]  
attachment =  zenpy_client.attachments.redact(ticket, the_comment, the_comment.attachments[0].id)

# Barring no errors, the attachment is an Attachment object with the same id as was passed in!
```

##### Creating a ticket with a custom field set

```python
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

```python
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

```python
# 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

```python
user = zenpy_client.users(id=user_id)
user.remote_photo_url = 'http://domain/example_photo.jpg'
zenpy_client.users.update(user)
```

##### List all categories from help center

```python
categories = zenpy_client.help_center.categories()
for category in categories:
    pass

```

##### List all help center articles

```python
articles = zenpy_client.help_center.articles(section=section)
for article in articles:
    pass
```

##### List all help center articles in a section

```python
section = zenpy_client.help_center.categories.sections(category_id=category.id)
articles = zenpy_client.help_center.sections.articles(section=section)
for article in articles:
    pass
```

##### Create new category in help center

```python
from zenpy import Zenpy
from zenpy.lib.api_objects.help_centre_objects import Category
new_category = zenpy_client.help_center.categories.create(
            Category(
                name="Category name",
                description="Category description",
                locale="en-us",
                created_at=datetime.now(),
                updated_at=datetime.now()
            )
        )
print(new_category.to_dict(serialize=True))
```

##### Create new section in help center

```python
from zenpy import Zenpy
from zenpy.lib.api_objects.help_centre_objects import Section
new_section = zenpy_client.help_center.sections.create(
            Section(
                name="Section name",
                description="Section description",
                category_id=new_category.id,
                locale="en-us",
                created_at=datetime.now(),
                updated_at=datetime.now()
            )
        )
print(new_section.to_dict(serialize=True))
```

##### Create new article in help center

```python
from zenpy import Zenpy
from zenpy.lib.api_objects.help_centre_objects import Article
new_article = zenpy_client.help_center.articles.create(
                    section=new_section.id,
                    article=Article(
                        name="Article Name",
                        body="<p>Article html content body</p>",
                        locale="en-us",
                        title="Article title",
                        section_id=new_section.id,
                        created_at=datetime.now(),
                        updated_at=datetime.now()
                    ),
                )
print(new_article.to_dict(serialize=True))
```

##### Working with webhooks

###### Show a webhook
```python
webhook = zenpy_client.webhooks(id=WEBHOOK_ID) 
```

###### List webhooks
```python
# Just list all the webhooks
for webhook in zenpy_client.webhooks.list():
    pass # Do something with it

# Filter the webhooks by a string in the name
for webhook in zenpy_client.webhooks.list(filter='some string'):
    pass # Do something with it

# Using sorting and pagination according to https://developer.zendesk.com/api-reference/event-connectors/webhooks/webhooks/#list-webhooks
zenpy_client.webhooks.list(sort='name')
zenpy_client.webhooks.list(page_before=X, page_size=Y)
zenpy_client.webhooks.list(page_after=N, page_size=Y)
```

###### Creating a webhook that uses basic authentication
```python
from zenpy.lib.api_objects import Webhook

new_webhook = Webhook(
    authentication={
        "add_position": "header",
        "data": {
            "password": "hello_123",
            "username": "john_smith"
        },
        "type": "basic_auth"
    },
    endpoint="https://example.com/status/200",
    http_method="GET",
    name="Example Webhook",
    description="Webhook description",
    request_format="json",
    status="active",
    subscriptions=["conditional_ticket_events"],
) 
zenpy_client.webhooks.create(new_webhook)
```

###### Creating a webhook that uses no authentication
```python
new_webhook = Webhook(
    endpoint="https://example.com/status/200",
    http_method="GET",
    name="Example Webhook",
    description="Webhook description",
    request_format="json",
    status="active",
    subscriptions=["conditional_ticket_events"],
) 
zenpy_client.webhooks.create(new_webhook)
```

###### Creating a webhook that uses bearer token authentication
```python
new_webhook = Webhook(
    authentication={
        "add_position": "header",
        "data": {
            "token": "{{token}}"
        },
        "type": "bearer_token"
    },
    # other fields
) 
zenpy_client.webhooks.create(new_webhook)
```

###### Updating a webhook
```python
from zenpy.lib.api_objects import Webhook

webhook = zenpy_client.webhooks(id=WEBHOOK_ID) 

# Note: We need a brand new object because of API specific requirements for 'update'
# https://developer.zendesk.com/api-reference/event-connectors/webhooks/webhooks/#update-webhook

new_webhook = Webhook(
                    name="New name",
                    request_format="json",
                    http_method="GET",
                    endpoint="https://example.com/status/200",
                    status="active",
                    authentication={
                      "add_position": "header",
                      "data": {
                          "password": "hello_123",     # As we can't get it back we need to pass it again from scratch
                          "username": "john_smith"
                      },
                      "type": "basic_auth"
                  },
)
response = zenpy_client.webhooks.update(webhook.id, new_webhook)
```

###### Partially updating (patching) a webhook
```python
webhook = zenpy_client.webhooks(id=WEBHOOK_ID)
webhook.name = 'A new name'
response = zenpy_client.webhooks.patch(webhook)
```

###### Cloning a webhook
```python
from zenpy.lib.api_objects import Webhook

an_existing_webhook = zenpy_client.webhooks(id=WEBHOOK_ID) 
new_webhook = zenpy_client.webhooks.clone(an_existing_webhook)

# Or just
new_webhook = zenpy_client.webhooks.clone(WEBHOOK_ID)
```

###### Working with secrets
```python

secret = zenpy_client.webhooks.show_secret(webhook)
print(secret.secret)

secret = zenpy_client.webhooks.reset_secret(webhook)
print(secret.secret)
```

###### Testing webhooks
```python

# Testing an existing webhook "as is""
response = zenpy_client.webhooks.test(webhook)

# Testing an existing webhook with modifications 
response = zenpy_client.webhooks.test(
                    webhook, 
                    request=dict(
                      endpoint='https://example.org/'
                    )
)

# Sending a test request without creating a webhook
response = zenpy_client.webhooks.test(
                    request=dict(
                        endpoint="https://example.org",
                        request_format="json",
                        http_method="GET",
                    )
                )
```

###### Getting a webhook invocations

[API documentation](https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#list-webhook-invocations)

```python
wh_filters = {
    'filter[from_ts]': '2023-12-04T12:00:00Z',
    'filter[to_ts]': '2023-12-04T16:00:00Z',
    'filter[status]': 'success',
}

for invocations in zenpy.webhooks.invocations(webhook_id, **wh_filters):
    pass

```

##### Pagination

Please refer to the [official documentation](https://developer.zendesk.com/api-reference/introduction/pagination/) to get details. Also check this article: [Which endpoints are supported?](https://support.zendesk.com/hc/en-us/articles/4408846180634#h_01FF626TG8VD0W4JP9DBBSXESK)

```python
# An old style offset pagination, not recommended. Since August 15, 2023, is limited to 100 pages.
fields = zenpy_client.ticket_fields()
# Or
fields = zenpy_client.ticket_fields(cursor_pagination=False)

# A new cursor offset pagination
fields = zenpy_client.ticket_fields(cursor_pagination=True) # is equal to 100 results per page
# Or
fields = zenpy_client.ticket_fields(cursor_pagination=50) # 50 results per page

```

## Documentation

Check out the [documentation](http://docs.facetoe.com.au/) for more info.

### Contributions
Contributions are very welcome. I've written an explanation of the core ideas of the wrapper in the [Contributors Guide](https://github.com/facetoe/zenpy/wiki/Contributors-Guide).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/facetoe/zenpy",
    "name": "zenpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "zendesk, api, wrapper",
    "author": "Face Toe",
    "author_email": "facetoe@facetoe.com.au",
    "download_url": "https://files.pythonhosted.org/packages/4f/85/1b5ebad3c35cdbbeffa46aae52fe04c155732a45317e766d91865691a890/zenpy-2.0.56.tar.gz",
    "platform": null,
    "description": "[![Build Status](https://travis-ci.org/facetoe/zenpy.svg?branch=master)](https://travis-ci.org/facetoe/zenpy)\n\n# Zenpy\n\nZenpy is a Python wrapper for the Zendesk, Chat and HelpCentre APIs. The goal of the project is to make it easy 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.\n\nZenpy supports both Python2 and Python3.\n\nPlease report bugs!\n\n* [Quickstart](#quickstart)\n* [Examples](#examples)\n  * Ticketing\n    * [Creating a ticket with a different requester](#creating-a-ticket-with-a-different-requester)\n    * [Commenting on a ticket](#commenting-on-a-ticket)\n    * [Adding a HTML comment to a ticket](#adding-a-html-comment-to-a-ticket)\n    * [Appending tags to a ticket](#appending-tags-to-a-ticket)\n    * [Uploading an attachment](#uploading-an-attachment)\n    * [Creating a ticket with a custom field set](#creating-a-ticket-with-a-custom-field-set)\n    * [Updating a custom field on a ticket](#updating-a-custom-field-on-a-ticket)\n    * [Applying a Macro to a ticket](#applying-a-macro-to-a-ticket)\n  * Users\n    * [Adding a photo to a user](#adding-a-photo-to-a-user)\n  * Help center\n    * [List all categories from help center](#List-all-categories-from-help-center)\n    * [List all help center articles](#List-all-help-center-articles)\n    * [List all help center articles in a section](#List-all-help-center-articles-in-a-section)\n    * [Create new category in help center](#Create-new-category-in-help-center)\n    * [Create new section in help center](#Create-new-section-in-help-center)\n    * [Create new article in help center](#Create-new-article-in-help-center)\n  * Other\n    * [Working with webhooks](#Working-with-webhooks)\n    * [Pagination](#Pagination)\n* [Documentation](#documentation)\n* [Contributions](#contributions)\n\n## Quickstart\n\n```python\nfrom zenpy import Zenpy\nfrom zenpy.lib.api_objects import Ticket\n# Create a Zenpy instance\nzenpy_client = Zenpy(**credentials)\n\n# Create a new ticket\nzenpy_client.tickets.create(Ticket(subject=\"Important\", description=\"Thing\"))\n\n# Perform a simple search\nfor ticket in zenpy_client.search('PC LOAD LETTER', type='ticket', assignee='facetoe'):\n    # No need to mess around with ids, linked objects can be accessed directly.\n    print(ticket.requester.name)\n\n    # All objects can be converted to a Python dict.\n    print(ticket.to_dict())\n\n    # Or to JSON.\n    print(ticket.to_json())\n```\n\n## Examples\n\n##### Searching open and pending tickets for a specific user and sort them by descending\n\n```python\nzenpy_client.search(type='ticket', status_less_than='closed', assignee='foo@mail.foo', sort_order='desc')\n```\n\n##### Searching only opened tickets\n\n```python\nzenpy_client.search(type='ticket', status='open')\n```\n\n##### Exporting all tickets matching the query\n\nBy default, Search API has a limit of 1000 results in total.\nSearch Export API allows exporting unlimited number of results, so if you'd like to export all results, \nuse this method instead:\n\n```python\nfor ticket in zenpy_client.search_export(type='ticket', status='open'):\n    print(ticket)\n```\n\nRead more about these limitations:\n\n[Search results limits](https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#results-limit)\n\n[Search Export API release notes](https://support.zendesk.com/hc/en-us/articles/4408825120538-Support-API-Announcing-the-Export-Search-Results-endpoint-)\n\n##### Creating a ticket with a different requester\n\n```python\nfrom zenpy.lib.api_objects import Ticket, User\n\nzenpy_client.tickets.create(\n    Ticket(description='Some description',\n           requester=User(name='bob', email='bob@example.com'))\n)\n```\n\n##### Commenting on a ticket\n\n```python\nfrom zenpy.lib.api_objects import Comment\n\nticket = zenpy_client.tickets(id=some_ticket_id)\nticket.comment = Comment(body=\"Important private comment\", public=False)\nzenpy_client.tickets.update(ticket)\n```\n\n##### Adding a HTML comment to a ticket\n\n```python\nfrom zenpy.lib.api_objects import Ticket, Comment\n\nzenpy_client.tickets.create(Ticket(\n    subject='Html comment example',\n    comment=Comment(body='The smoke is very colorful',\n                    html_body='<h2>The smoke is <i>very</i> colourful</h2>'))\n)\n```\n\n##### Appending tags to a ticket\n\n```python\nfrom zenpy.lib.api_objects import Ticket\n\nticket = zenpy_client.tickets(id=some_ticket_id)\nticket.tags.extend(['onetag', 'twotag', 'threetag', 'four'])\nzenpy_client.tickets.update(ticket)\n```\n\n##### Uploading an attachment\n\n```python\nfrom zenpy.lib.api_objects import Comment\n\n# Upload the file (or file-like object) to Zendesk and obtain an Upload instance\nupload_instance = zenpy_client.attachments.upload('/tmp/awesome_file.txt')\n\nticket = zenpy_client.tickets(id=some_ticket_id)\nticket.comment = Comment(body='This comment has my file attached', uploads=[upload_instance.token])\nzenpy_client.tickets.update(ticket)\n```\n\n##### Creating a comment attachment and then redacting it\n\n```python\n# Upload the attachment\nupload_instance = zenpy_client.attachments.upload('/tmp/awesome_file.txt')\ncomment = Comment(body='Some comment')\n# Set the comment attachment affinity to this token.\ncomment.uploads = upload_instance.token\n\n# Create the ticket, with that comment with that attachment affinity.  Can just as easily be a new comment on existing ticket.\nticket = Ticket(subject='example ticket', comment=comment)\nticket_audit = zenpy_client.tickets.create(ticket)\nticket = ticket_audit.ticket\n\n# Get the last comment we just uploaded on that ticket.\nthe_commentresult = zenpy_client.tickets.comments(ticket)\n\n# Redact the comment now that we just associated it with an attachment.\nthe_comment = the_commentresult.values[0]  \nattachment =  zenpy_client.attachments.redact(ticket, the_comment, the_comment.attachments[0].id)\n\n# Barring no errors, the attachment is an Attachment object with the same id as was passed in!\n```\n\n##### Creating a ticket with a custom field set\n\n```python\nfrom zenpy.lib.api_objects import CustomField, Ticket\n\nticket_audit = zenpy_client.tickets.create(Ticket(\n    subject='Has custom field',\n    description=\"Wow, such field\",\n    custom_fields=[CustomField(id=43528467, value=1337)]\n))\n```\n\n##### Updating a custom field on a ticket\n\n```python\nfrom zenpy.lib.api_objects import CustomField\nticket = zenpy_client.tickets(id=some_ticket_id)\nticket.custom_fields.append(CustomField(id=43528467, value=1337))\nzenpy_client.tickets.update(ticket)\n```\n\n##### Applying a Macro to a ticket\n\n```python\n# Execute the show_macro_effect() method which returns what the macro *would* do.\n# The method accepts either Zenpy objects or ids.\nmacro_result = zenpy_client.tickets.show_macro_effect(ticket_id_or_object, macro_id_or_object)\n\n# Update the ticket to actually change the ticket.\nzenpy_client.tickets.update(macro_result.ticket)\n```\n\n##### Adding a photo to a user\n\n```python\nuser = zenpy_client.users(id=user_id)\nuser.remote_photo_url = 'http://domain/example_photo.jpg'\nzenpy_client.users.update(user)\n```\n\n##### List all categories from help center\n\n```python\ncategories = zenpy_client.help_center.categories()\nfor category in categories:\n    pass\n\n```\n\n##### List all help center articles\n\n```python\narticles = zenpy_client.help_center.articles(section=section)\nfor article in articles:\n    pass\n```\n\n##### List all help center articles in a section\n\n```python\nsection = zenpy_client.help_center.categories.sections(category_id=category.id)\narticles = zenpy_client.help_center.sections.articles(section=section)\nfor article in articles:\n    pass\n```\n\n##### Create new category in help center\n\n```python\nfrom zenpy import Zenpy\nfrom zenpy.lib.api_objects.help_centre_objects import Category\nnew_category = zenpy_client.help_center.categories.create(\n            Category(\n                name=\"Category name\",\n                description=\"Category description\",\n                locale=\"en-us\",\n                created_at=datetime.now(),\n                updated_at=datetime.now()\n            )\n        )\nprint(new_category.to_dict(serialize=True))\n```\n\n##### Create new section in help center\n\n```python\nfrom zenpy import Zenpy\nfrom zenpy.lib.api_objects.help_centre_objects import Section\nnew_section = zenpy_client.help_center.sections.create(\n            Section(\n                name=\"Section name\",\n                description=\"Section description\",\n                category_id=new_category.id,\n                locale=\"en-us\",\n                created_at=datetime.now(),\n                updated_at=datetime.now()\n            )\n        )\nprint(new_section.to_dict(serialize=True))\n```\n\n##### Create new article in help center\n\n```python\nfrom zenpy import Zenpy\nfrom zenpy.lib.api_objects.help_centre_objects import Article\nnew_article = zenpy_client.help_center.articles.create(\n                    section=new_section.id,\n                    article=Article(\n                        name=\"Article Name\",\n                        body=\"<p>Article html content body</p>\",\n                        locale=\"en-us\",\n                        title=\"Article title\",\n                        section_id=new_section.id,\n                        created_at=datetime.now(),\n                        updated_at=datetime.now()\n                    ),\n                )\nprint(new_article.to_dict(serialize=True))\n```\n\n##### Working with webhooks\n\n###### Show a webhook\n```python\nwebhook = zenpy_client.webhooks(id=WEBHOOK_ID) \n```\n\n###### List webhooks\n```python\n# Just list all the webhooks\nfor webhook in zenpy_client.webhooks.list():\n    pass # Do something with it\n\n# Filter the webhooks by a string in the name\nfor webhook in zenpy_client.webhooks.list(filter='some string'):\n    pass # Do something with it\n\n# Using sorting and pagination according to https://developer.zendesk.com/api-reference/event-connectors/webhooks/webhooks/#list-webhooks\nzenpy_client.webhooks.list(sort='name')\nzenpy_client.webhooks.list(page_before=X, page_size=Y)\nzenpy_client.webhooks.list(page_after=N, page_size=Y)\n```\n\n###### Creating a webhook that uses basic authentication\n```python\nfrom zenpy.lib.api_objects import Webhook\n\nnew_webhook = Webhook(\n    authentication={\n        \"add_position\": \"header\",\n        \"data\": {\n            \"password\": \"hello_123\",\n            \"username\": \"john_smith\"\n        },\n        \"type\": \"basic_auth\"\n    },\n    endpoint=\"https://example.com/status/200\",\n    http_method=\"GET\",\n    name=\"Example Webhook\",\n    description=\"Webhook description\",\n    request_format=\"json\",\n    status=\"active\",\n    subscriptions=[\"conditional_ticket_events\"],\n) \nzenpy_client.webhooks.create(new_webhook)\n```\n\n###### Creating a webhook that uses no authentication\n```python\nnew_webhook = Webhook(\n    endpoint=\"https://example.com/status/200\",\n    http_method=\"GET\",\n    name=\"Example Webhook\",\n    description=\"Webhook description\",\n    request_format=\"json\",\n    status=\"active\",\n    subscriptions=[\"conditional_ticket_events\"],\n) \nzenpy_client.webhooks.create(new_webhook)\n```\n\n###### Creating a webhook that uses bearer token authentication\n```python\nnew_webhook = Webhook(\n    authentication={\n        \"add_position\": \"header\",\n        \"data\": {\n            \"token\": \"{{token}}\"\n        },\n        \"type\": \"bearer_token\"\n    },\n    # other fields\n) \nzenpy_client.webhooks.create(new_webhook)\n```\n\n###### Updating a webhook\n```python\nfrom zenpy.lib.api_objects import Webhook\n\nwebhook = zenpy_client.webhooks(id=WEBHOOK_ID) \n\n# Note: We need a brand new object because of API specific requirements for 'update'\n# https://developer.zendesk.com/api-reference/event-connectors/webhooks/webhooks/#update-webhook\n\nnew_webhook = Webhook(\n                    name=\"New name\",\n                    request_format=\"json\",\n                    http_method=\"GET\",\n                    endpoint=\"https://example.com/status/200\",\n                    status=\"active\",\n                    authentication={\n                      \"add_position\": \"header\",\n                      \"data\": {\n                          \"password\": \"hello_123\",     # As we can't get it back we need to pass it again from scratch\n                          \"username\": \"john_smith\"\n                      },\n                      \"type\": \"basic_auth\"\n                  },\n)\nresponse = zenpy_client.webhooks.update(webhook.id, new_webhook)\n```\n\n###### Partially updating (patching) a webhook\n```python\nwebhook = zenpy_client.webhooks(id=WEBHOOK_ID)\nwebhook.name = 'A new name'\nresponse = zenpy_client.webhooks.patch(webhook)\n```\n\n###### Cloning a webhook\n```python\nfrom zenpy.lib.api_objects import Webhook\n\nan_existing_webhook = zenpy_client.webhooks(id=WEBHOOK_ID) \nnew_webhook = zenpy_client.webhooks.clone(an_existing_webhook)\n\n# Or just\nnew_webhook = zenpy_client.webhooks.clone(WEBHOOK_ID)\n```\n\n###### Working with secrets\n```python\n\nsecret = zenpy_client.webhooks.show_secret(webhook)\nprint(secret.secret)\n\nsecret = zenpy_client.webhooks.reset_secret(webhook)\nprint(secret.secret)\n```\n\n###### Testing webhooks\n```python\n\n# Testing an existing webhook \"as is\"\"\nresponse = zenpy_client.webhooks.test(webhook)\n\n# Testing an existing webhook with modifications \nresponse = zenpy_client.webhooks.test(\n                    webhook, \n                    request=dict(\n                      endpoint='https://example.org/'\n                    )\n)\n\n# Sending a test request without creating a webhook\nresponse = zenpy_client.webhooks.test(\n                    request=dict(\n                        endpoint=\"https://example.org\",\n                        request_format=\"json\",\n                        http_method=\"GET\",\n                    )\n                )\n```\n\n###### Getting a webhook invocations\n\n[API documentation](https://developer.zendesk.com/api-reference/webhooks/webhooks-api/webhooks/#list-webhook-invocations)\n\n```python\nwh_filters = {\n    'filter[from_ts]': '2023-12-04T12:00:00Z',\n    'filter[to_ts]': '2023-12-04T16:00:00Z',\n    'filter[status]': 'success',\n}\n\nfor invocations in zenpy.webhooks.invocations(webhook_id, **wh_filters):\n    pass\n\n```\n\n##### Pagination\n\nPlease refer to the [official documentation](https://developer.zendesk.com/api-reference/introduction/pagination/) to get details. Also check this article: [Which endpoints are supported?](https://support.zendesk.com/hc/en-us/articles/4408846180634#h_01FF626TG8VD0W4JP9DBBSXESK)\n\n```python\n# An old style offset pagination, not recommended. Since August 15, 2023, is limited to 100 pages.\nfields = zenpy_client.ticket_fields()\n# Or\nfields = zenpy_client.ticket_fields(cursor_pagination=False)\n\n# A new cursor offset pagination\nfields = zenpy_client.ticket_fields(cursor_pagination=True) # is equal to 100 results per page\n# Or\nfields = zenpy_client.ticket_fields(cursor_pagination=50) # 50 results per page\n\n```\n\n## Documentation\n\nCheck out the [documentation](http://docs.facetoe.com.au/) for more info.\n\n### Contributions\nContributions are very welcome. I've written an explanation of the core ideas of the wrapper in the [Contributors Guide](https://github.com/facetoe/zenpy/wiki/Contributors-Guide).\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Python wrapper for the Zendesk API",
    "version": "2.0.56",
    "project_urls": {
        "Download": "https://github.com/facetoe/zenpy/releases/tag/2.0.56",
        "Homepage": "https://github.com/facetoe/zenpy"
    },
    "split_keywords": [
        "zendesk",
        " api",
        " wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6f19f6332b75ef6bc270f063af5101202a6fe1c1ef7ef41e43ca013f7871c07",
                "md5": "7060a7118690527e7d60a83676840efb",
                "sha256": "7cd73421f9903034b53fbe32968359574892e29410db1895f999f5bacb4c91db"
            },
            "downloads": -1,
            "filename": "zenpy-2.0.56-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7060a7118690527e7d60a83676840efb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 89201,
            "upload_time": "2024-11-21T02:20:07",
            "upload_time_iso_8601": "2024-11-21T02:20:07.473729Z",
            "url": "https://files.pythonhosted.org/packages/a6/f1/9f6332b75ef6bc270f063af5101202a6fe1c1ef7ef41e43ca013f7871c07/zenpy-2.0.56-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4f851b5ebad3c35cdbbeffa46aae52fe04c155732a45317e766d91865691a890",
                "md5": "8704248aa97300673c955b9fa8a4b285",
                "sha256": "984cdcd93dde5d70fa0e2d5c1d1878b8700dc26df63ca3414f6b55577423cb1c"
            },
            "downloads": -1,
            "filename": "zenpy-2.0.56.tar.gz",
            "has_sig": false,
            "md5_digest": "8704248aa97300673c955b9fa8a4b285",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 87614,
            "upload_time": "2024-11-21T02:20:09",
            "upload_time_iso_8601": "2024-11-21T02:20:09.408476Z",
            "url": "https://files.pythonhosted.org/packages/4f/85/1b5ebad3c35cdbbeffa46aae52fe04c155732a45317e766d91865691a890/zenpy-2.0.56.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-21 02:20:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "facetoe",
    "github_project": "zenpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [
        {
            "name": "cachetools",
            "specs": [
                [
                    ">=",
                    "3.1.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.14.2"
                ]
            ]
        },
        {
            "name": "pytz",
            "specs": [
                [
                    ">=",
                    "2018.9"
                ]
            ]
        },
        {
            "name": "python-dateutil",
            "specs": [
                [
                    ">=",
                    "2.7.5"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    ">=",
                    "1.14.0"
                ]
            ]
        }
    ],
    "lcname": "zenpy"
}
        
Elapsed time: 0.40514s