Client
- exception APIException(...)
Raised when the API server indicates an error.
- class Pagination(per_page=10, expand=False)
pagination settings for recources
.search()and.iter()methods- expand: bool = False
if
Truethe server will send additional properties for each resource
- per_page: int = 10
number of returned objects per page request
- class Client(url, *, http_auth=None, http_token=None, oauth2_token=None, additional_headers=())
The root class to interact with the REST API.
Almost every object keeps the initialized instance of
Clientas reference.Example:
from zammadoo import Client # basic authentication scheme client = Client("https://myhost.com/api/v1/", http_auth=("<username>", "<mysecret>")) # token based authentication client = Client("https://myhost.com/api/v1/", http_token="<secret_token>") # authenticate with bearer token (OAuth 2.0) client = Client("https://myhost.com/api/v1/", oauth2_token="<secret_token>")
For authentication use either
http_authorhttp_tokenoroauth2_token.- Parameters:
url (str) – the zammad API url (e.g.
https://myhost.com/api/v1)http_auth (Tuple[str, str] | None) – username and password for HTTP Basic Authentication
http_token (str | None) – access token when using HTTP Token Authentication
oauth2_token (str | None) – access token when using OAuth 2 Authentication
additional_headers (Sequence[Tuple[str, str]]) – additional name, value pairs that will be appended to the requests header
[(name, value), ...]
- Raises:
ValueErrorif authentication settings are missing.
- impersonation_of(user)
Temporarily perform requests on behalf of another user.
To be used as context manager:
with client.impersonation_of(1): print(client.users.me().id) # output: 1
- Parameters:
user (str | int) – user id or login_name
- request(method, *args, params=None, json=None, **kwargs)
Perform a request on the API URL.
- Parameters:
method (str) – HTTP method: e.g.
GET,POST,PUT,DELETEargs – endpoint specifiers
params (StringKeyMapping | None) – URL parameter (usually for
GET)json (StringKeyMapping | None) – data as dictionary (usually for
POSTorPUT)kwargs – additional parameters passed to
request()
- Returns:
the server JSON response
- Return type:
StringKeyDict
- Raises:
APIException,requests.HTTPError
- response(method, url, params=None, json=None, **kwargs)
Perform a request on the API URL.
- Parameters:
method (str) – the HTTP method (e.g.
GET,POST,PUT,DELETE)url (str) – full resource URL
params (StringKeyMapping | None) – parameter that get urlencoded (usually for
GET)json (StringKeyMapping | None) – data as dictionary (usually for
POSTorPUT)kwargs – additional parameters passed to
request()
- Return type:
requests.Response
- property notificatons: Notifications
Manages the
/online_notificationsendpoint.
- property organizations: Organizations
Manages the
/organizationsendpoint.
- pagination: Pagination
initial Pagination settings
- property server_version: str
the Zammad server version
- session: Session
the requests Session instance
- property ticket_priorities: Priorities
Manages the
/ticket_prioritiesendpoint.
- property time_accountings: TimeAccountings
Manages the
/time_accountingsendpoint.
- url: str
the clients API URL
- property weburl: str