BankAPI class

class BankAPI(parent)

Bases: FreeAgentBase

BankAPI class to retreive information about bank accounts on freeagent

Initialize the base class

Parameters:

api_base_url – the url to use for requests, defaults to normal but can be changed to sandbox

attach_file_to_explanation(payload, path, description=None)

Attach a file to an existing ExplanationPayload freeagent supports:

  • image/x-png

  • image/jpeg

  • image/jpg

  • image/gif

  • application/x-pdf

Parameters:
  • payload (ExplanationPayload) – ExplanationPayload to add the file to

  • description (str) – optional description to use for the file on freeagent

authenticate(oauth_ident, oauth_secret, save_token_cb, token=None)

Authenticate with the freeagent API

Parameters:
  • oauth_ident (str) – oauth identifier from the freeagent dev dashboard

  • oauth_secret (str) – oauth secret from the freeagent dev dashboard

  • save_token_cb – function to call when the token is refreshed to save it

  • token (str) – initial token, or None

explain_list(items, dryrun=False, separator=None)

Iterate through a list of UpdatePayload or ExplanationPayload and call explain_update or explain_transaction accordingly.

Parameters:
  • items (list) – list of UpdatePayload or ExplanationPayload objects

  • dryrun (bool) – if True then do not post to freeagent, only print details

  • separator (str) – optional string to replace with newlines in description for table output

explain_transaction(tx_obj, printout=True, dryrun=False)

Post the explanation to freeagent in the passed ExplanationPayload tx_obj

Parameters:
  • tx_obj (ExplanationPayload) – ExplanationPayload to use

  • printout (bool) – Print out the desciption and gross value

  • dry_run – if True then do not post to freeagent, only print details

explain_update(url, tx_obj, printout=True, dryrun=False)

Update an existing explanation on freeagent with the passed url

Parameters:
  • url (str) – url attribute of the bank transaction explanation to change

  • tx_obj (ExplanationPayload) – ExplanationPayload to use for updating the explanation

  • printout (bool) – Print out the desciption and gross value

  • dry_run – if True then do not post to freeagent, only print details

get_api(endpoint, params=None)

Perform an API get request, handling pagination

Parameters:
  • endpoint (str) – end part of the endpoint URL

  • params (dict) – dict of “Name”: Value entries for request to process into URL

Return type:

list

Returns:

A list of dataclass instances

get_unexplained_transactions(account_id)

Return a list of unexplained transaction objects for the bank account with id of account_id

Parameters:

account_id (str) – account id to use, or the whole url

Return type:

list

Returns:

list of the unexplained transactions

post_api(endpoint, root, payload)

Perform an API post request

Parameters:
  • endpoint (str) – end part of url endpoint

  • root (str) – first part of payload

  • payload (str) – second part of payload

Raises:

RunTimeError – if post request fails

put_api(url, root, updates)

Perform an API put request

Parameters:
  • url (str) – complete url for put request

  • root (str) – first part of payload

  • updates (str) – second part of payload

Raises:

RunTimeError – if put request fails

serialize_for_api(obj)

Convert dataclasses or dicts with Decimal, date, etc. into plain API-compatible dicts

Parameters:

obj – dataclass or dict to convert

Return type:

dict[str, any]

return: API-compatible dict