Skip to content

Client

client

Client for the HelpDesk / LiveChat API

Documentation: https://api.helpdesk.com/docs

ToDo

JSON = Union[JSONObj, JSONLst] module-attribute

Type of the JSON response as returned by the HelpDesk / LiveChat API

JSONLst = List[JSONObj] module-attribute

Type of a JSON list of JSON objects

JSONObj = Dict[str, Any] module-attribute

Type of a JSON object (without recursion)

HelpDeskClient(config: Optional[Config] = None)

Source code in pytanis/helpdesk/client.py
def __init__(self, config: Optional[Config] = None):
    if config is None:
        config = get_cfg()
    self._config = config
    # Important: Always use a custom User-Agent, never a generic one.
    # Generic User-Agents are filtered by helpdesk to reduce spam.
    self._headers = {"User-Agent": "Pytanis"}

    self._get_throttled = self._get
    self._post_throttled = self._post
    self.set_throttling(2, 1)  # we are nice by default

create_ticket(ticket: NewTicket)

Source code in pytanis/helpdesk/client.py
def create_ticket(self, ticket: NewTicket):
    return self.post("tickets", data=ticket.dict())

get(endpoint: str, params: Optional[Dict[str, str]] = None) -> JSON

Retrieve data via throttled GET request and return the JSON

Source code in pytanis/helpdesk/client.py
def get(self, endpoint: str, params: Optional[Dict[str, str]] = None) -> JSON:
    """Retrieve data via throttled GET request and return the JSON"""
    resp = self._get_throttled(endpoint, params)
    resp.raise_for_status()
    return resp.json()

list_agents() -> List[Agent]

Source code in pytanis/helpdesk/client.py
def list_agents(self) -> List[Agent]:
    agents = self.get("agents")
    assert isinstance(agents, List)
    return [Agent.parse_obj(dct) for dct in agents]

list_teams() -> List[Team]

Source code in pytanis/helpdesk/client.py
def list_teams(self) -> List[Team]:
    teams = self.get("teams")
    assert isinstance(teams, List)
    return [Team.parse_obj(dct) for dct in teams]

post(endpoint: str, data: Dict[str, Any], params: Optional[Dict[str, str]] = None) -> JSON

Source code in pytanis/helpdesk/client.py
def post(self, endpoint: str, data: Dict[str, Any], params: Optional[Dict[str, str]] = None) -> JSON:
    resp = self._post_throttled(endpoint, data, params)
    resp.raise_for_status()
    return resp.json()

set_throttling(calls: int, seconds: int)

Throttle the number of calls per seconds to the Pretalx API

Source code in pytanis/helpdesk/client.py
def set_throttling(self, calls: int, seconds: int):
    """Throttle the number of calls per seconds to the Pretalx API"""
    _logger.debug("throttling", calls=calls, seconds=seconds)
    self._get_throttled = throttle(calls, seconds)(self._get)
    self._post_throttled = throttle(calls, seconds)(self._post)