zendesk_sdk

Interface to Zendesk API.

Submodules

Exceptions

TicketClosedError

Raised when a ticket is closed.

TicketUpdateConflictError

Raised when a safe update finds the ticket changed after updated_stamp.

Classes

ZendeskServices

A class wrapping Zendesk interaction.

Attachment

Attachment model.

IncrementalTicketPage

One page of the incremental ticket export for the caller to traverse.

Ticket

Ticket model.

TicketAudit

One update to a ticket: who made it, when, and what it changed.

TicketAuditEvent

One thing an audit did to its ticket.

TicketAuditPage

One cursor page of a ticket's audits for the caller to traverse.

TicketComment

One comment on a ticket, public or internal.

TicketCommentPage

One cursor page of ticket comments for the caller to traverse.

User

A Zendesk user: an end user (requester) or a staff member.

Package Contents

class zendesk_sdk.ZendeskServices(base_url: str, client_id: str, client_secret: str, scope: str, timeout: float)[source]

A class wrapping Zendesk interaction.

client[source]
_client_id[source]
_client_secret[source]
_scope[source]
_access_token: str | None = None[source]
_access_token_expires_at[source]
_get_access_token() → str[source]

Return an access token, requesting a new one when the cached one has expired.

_make_request(method: str, path: str, params: dict[str, Any] | None = None, json: dict[str, Any] | None = None, headers: dict[str, str] | None = None) → niquests.Response[source]

Make a request to Zendesk.

search(type_: Literal['ticket', 'user', 'organization'] = 'ticket', statuses: list[Literal['new', 'open', 'pending', 'hold', 'solved', 'closed']] | None = None, tags: list[str] | None = None) → list[zendesk_sdk.models.Ticket][source]

Search.

get_ticket(ticket_id: int) → zendesk_sdk.models.Ticket[source]

Find and load to base64.

create_ticket(subject: str, body: str, *, requester_email: str, requester_name: str, email_ccs: list[str] | None = None, tags: list[str] | None = None, group_id: int | None = None, priority: Literal['urgent', 'high', 'normal', 'low'] = 'normal', external_id: str | None = None, idempotency_key: str | None = None, comment_is_public: bool = True) → zendesk_sdk.models.Ticket[source]

Create a ticket on behalf of a requester.

email_ccs are the addresses copied on the ticket besides the requester. They are sent as given, so the caller decides what counts as a duplicate.

update_ticket(ticket_id: int, status: Literal['new', 'open', 'pending', 'hold', 'solved', 'closed'] | None = None, comment: str | None = None, comment_is_public: bool = True, *, updated_stamp: datetime.datetime | None = None) → zendesk_sdk.models.Ticket[source]

Update a ticket, checking for concurrent changes when updated_stamp is provided.

add_tags_to_ticket(ticket_id: int, tags: list[str]) → list[str][source]

Add tags to a ticket.

get_ticket_comments(ticket_id: int) → collections.abc.Iterator[zendesk_sdk.models.TicketComment][source]

Yield a ticket’s comments, fetching the next page only when the caller reaches it.

get_ticket_comments_page(ticket_id: int, *, after_cursor: str | None = None) → zendesk_sdk.models.TicketCommentPage[source]

Return one cursor page of comments; the caller follows after_cursor if has_more.

get_ticket_audits(ticket_id: int) → collections.abc.Iterator[zendesk_sdk.models.TicketAudit][source]

Yield a ticket’s audits, fetching the next page only when the caller reaches it.

An audit is one update to the ticket: its author, its time and the events it made, a field’s old and new value among them. Zendesk documents no order for them, so sort by created_at to replay a ticket’s history. The token needs the global read scope; Zendesk refuses tickets:read for audits.

get_ticket_audits_page(ticket_id: int, *, after_cursor: str | None = None) → zendesk_sdk.models.TicketAuditPage[source]

Return one cursor page of audits; the caller follows after_cursor if has_more.

Zendesk does not paginate the audits of an archived ticket: it answers them all with no pagination metadata, which is read as a last page.

get_users(user_ids: list[int]) → list[zendesk_sdk.models.User][source]

Return the users with these ids, in one request; unknown ids are left out.

download_attachment(attachment: zendesk_sdk.models.Attachment) → bytes[source]

Return an attachment’s bytes, read from its content_url.

Zendesk answers with a redirect to a signed download, which is followed. The token needs the ticket_attachments:read scope (or read) when the account keeps attachments private.

get_incremental_tickets_page(*, start_time: datetime.datetime | None = None, cursor: str | None = None, include_deleted: bool = False) → zendesk_sdk.models.IncrementalTicketPage[source]

Return one page of tickets changed since start_time, or since a previous page’s cursor.

Pass start_time on the first call only, then the after_cursor of the page before. end_of_stream says the caller has caught up; keep the cursor and ask again later. Zendesk allows this export to admins only, about ten requests a minute.

include_deleted keeps deleted tickets (spam among them) in the export, with the status deleted; pass the same value on every page of one walk.

exception zendesk_sdk.TicketClosedError[source]

Bases: Exception

Raised when a ticket is closed.

exception zendesk_sdk.TicketUpdateConflictError[source]

Bases: Exception

Raised when a safe update finds the ticket changed after updated_stamp.

class zendesk_sdk.Attachment(/, **data: Any)[source]

Bases: _BaseModel

Attachment model.

id: int[source]
url: str[source]
file_name: str[source]
content_url: str[source]
content_type: str | None = None[source]
size: int | None = None[source]
class zendesk_sdk.IncrementalTicketPage(/, **data: Any)[source]

Bases: _BaseModel

One page of the incremental ticket export for the caller to traverse.

tickets: list[Ticket][source]
after_cursor: str | None[source]
end_of_stream: bool[source]
class zendesk_sdk.Ticket(/, **data: Any)[source]

Bases: _BaseModel

Ticket model.

id: int[source]
status: Literal['new', 'open', 'pending', 'hold', 'solved', 'closed', 'deleted'][source]
url: str[source]
created_at: datetime.datetime[source]
updated_at: datetime.datetime[source]
tags: list[str][source]
subject: str | None = None[source]
description: str | None = None[source]
priority: Literal['urgent', 'high', 'normal', 'low'] | None = None[source]
requester_id: int | None = None[source]
submitter_id: int | None = None[source]
assignee_id: int | None = None[source]
group_id: int | None = None[source]
collaborator_ids: list[int][source]
class zendesk_sdk.TicketAudit(/, **data: Any)[source]

Bases: _BaseModel

One update to a ticket: who made it, when, and what it changed.

author_id is whoever made the update. An update a trigger or an automation made names no user Zendesk can load, so look the id up before treating it as a person.

metadata is Zendesk’s own record of where the update came from, passed through as sent. Zendesk documents its system and custom objects and not their keys, so read a key as optional.

id: int[source]
ticket_id: int[source]
created_at: datetime.datetime[source]
author_id: int | None = None[source]
metadata: dict[str, Any][source]
events: list[TicketAuditEvent][source]
class zendesk_sdk.TicketAuditEvent(/, **data: Any)[source]

Bases: _BaseModel

One thing an audit did to its ticket.

type says which: Create set a field as the ticket was opened, Change moved one, Comment added a comment, and Zendesk has many more. Only Create and Change carry field_name, and only Change carries previous_value. A value is normally a string, an id included ("360004442691"); tags are a list, and some fields are an object.

id: int[source]
type: str[source]
field_name: str | None = None[source]
value: str | int | bool | list[Any] | dict[str, Any] | None = None[source]
previous_value: str | int | bool | list[Any] | dict[str, Any] | None = None[source]
class zendesk_sdk.TicketAuditPage(/, **data: Any)[source]

Bases: _BaseModel

One cursor page of a ticket’s audits for the caller to traverse.

audits: list[TicketAudit][source]
has_more: bool[source]
after_cursor: str | None[source]
class zendesk_sdk.TicketComment(/, **data: Any)[source]

Bases: _BaseModel

One comment on a ticket, public or internal.

id: int[source]
public: bool[source]
plain_body: str[source]
html_body: str | None = None[source]
attachments: list[Attachment][source]
author_id: int | None = None[source]
created_at: datetime.datetime | None[source]
class zendesk_sdk.TicketCommentPage(/, **data: Any)[source]

Bases: _BaseModel

One cursor page of ticket comments for the caller to traverse.

comments: list[TicketComment][source]
has_more: bool[source]
after_cursor: str | None[source]
class zendesk_sdk.User(/, **data: Any)[source]

Bases: _BaseModel

A Zendesk user: an end user (requester) or a staff member.

id: int[source]
name: str[source]
email: str | None[source]
role: Literal['end-user', 'agent', 'admin'][source]