ds_provider_tripletex_py_lib.linked_service.tripletex

File: tripletex.py Region: ds_provider_tripletex_py_lib/linked_service/tripletex

Linked service for the Tripletex accounting API.

Tripletex authenticates via a two-step token exchange: a long-lived consumer token + per-employee employee token are exchanged for a short-lived session token, combined with client_id into an HTTP Basic Authorization header (Basic base64(client_id:session_token)). This doesn’t fit any of ds_protocol_http_py_lib’s built-in AuthType handlers, so connect() is fully overridden; transport (retries, timeouts, rate limiting) is still inherited from HttpLinkedService.

Example

>>> linked_service = TripletexLinkedService(
...     settings=TripletexLinkedServiceSettings(
...         consumer_token="my-consumer-token",
...         employee_token="my-employee-token",
...         client_id="my-client-id",
...     ),
... )
>>> linked_service.connect()
>>> linked_service.connection.get(f"{linked_service.settings.host}/company")
>>> linked_service.close()

Attributes

TripletexLinkedServiceSettingsType

Classes

TripletexLinkedServiceSettings

Settings required to connect to the Tripletex API.

TripletexLinkedService

Linked service for connecting to the Tripletex API.

Module Contents

class ds_provider_tripletex_py_lib.linked_service.tripletex.TripletexLinkedServiceSettings[source]

Bases: ds_protocol_http_py_lib.HttpLinkedServiceSettings

Settings required to connect to the Tripletex API.

consumer_token

Long-lived consumer token issued to the integration. Masked in logs.

employee_token

Per-employee token issued by the Tripletex user. Masked in logs.

client_id

Client identifier combined with the session token to form the Basic auth header. Tripletex accepts "0" for the default/anonymous client.

host

API host. Defaults to the production host; pass host= explicitly to target a different environment.

session_token_ttl_days

Requested validity window, in days, for the session token created during connect().

auth_type

Unused by this provider – connect() is fully overridden and never dispatches through the base class’s auth handlers. Kept only for schema/dataclass alignment with HttpLinkedServiceSettings.

consumer_token: str

Long-lived consumer token issued to the integration.

employee_token: str

Per-employee token issued by the Tripletex user.

client_id: str = '0'

Client identifier combined with the session token to form the Basic auth header.

host: str = 'https://tripletex.no/v2'

API host. Defaults to the Tripletex production environment.

session_token_ttl_days: int = 1

Requested validity window, in days, for the session token.

auth_type: ds_protocol_http_py_lib.enums.AuthType

Unused – connect() is fully overridden. Kept for dataclass alignment.

ds_provider_tripletex_py_lib.linked_service.tripletex.TripletexLinkedServiceSettingsType
class ds_provider_tripletex_py_lib.linked_service.tripletex.TripletexLinkedService[source]

Bases: ds_protocol_http_py_lib.HttpLinkedService[TripletexLinkedServiceSettingsType], Generic[TripletexLinkedServiceSettingsType]

Linked service for connecting to the Tripletex API.

Exposed (caller-configurable): id, name, description, version, settings. Internal (inherited from HttpLinkedService, init=False, never user-settable): _session, _http – runtime connection state populated by connect().

settings: TripletexLinkedServiceSettingsType
property type: ds_provider_tripletex_py_lib.enums.ResourceType

Return the resource type for the Tripletex linked service.

connect() → None[source]

Exchange consumer/employee tokens for a session token and build the auth header.

PUT``s ``{host}/token/session/:create with consumerToken/ employeeToken/expirationDate, reads the session token from value.token, then stores Basic base64(client_id:session_token) as the Authorization header. Idempotent – each call creates a fresh session token.

Raises:
  • AuthenticationError – If Tripletex responds but rejects the consumer/employee token (any non-2xx response other than 403, e.g. a revoked or malformed employee token returns 404/422, not 401 – Tripletex’s own message is included), or if the session token is missing from an otherwise-successful response.

  • AuthorizationError – If Tripletex returns 403 (authenticated but insufficient permission).

  • ConnectionError – If the request to Tripletex fails at the network level, or Tripletex never responds at all (e.g. a timeout) – distinct from a response that arrives but rejects the request.

test_connection() → tuple[bool, str][source]

Verify the Tripletex session by calling the lightweight identity endpoint.

Returns:

(True, "") on success, otherwise (False, error_message).

Return type:

tuple[bool, str]