The Transactions resource: retrieving, listing (with lazy pagination), and annotating transactions.
Summary
Functions
Sets or deletes key/value metadata on a transaction. Set a value to an
empty string to delete that key. Setting the reserved "notes" key
updates the transaction's top-level notes field instead.
Returns a single page of transactions for an account.
Fetches a single transaction by id, optionally expanding :merchant inline.
Returns a lazy Stream that walks every transaction for an account,
oldest first, across as many pages as needed - fetching each page only
as the stream is consumed.
Types
@type expand_field() :: :merchant
@type list_params() :: %{ :account_id => String.t(), optional(:since) => String.t(), optional(:before) => String.t(), optional(:limit) => pos_integer(), optional(:expand) => [expand_field()] }
@type retrieve_params() :: %{ :transaction_id => String.t(), optional(:expand) => [expand_field()] }
@type stream_params() :: %{ :account_id => String.t(), optional(:before) => String.t(), optional(:expand) => [expand_field()], optional(:since) => String.t(), optional(:page_size) => pos_integer() }
Functions
@spec annotate(Monzo.Client.t(), annotate_params()) :: {:ok, Monzo.Transaction.t()} | {:error, Exception.t()}
Sets or deletes key/value metadata on a transaction. Set a value to an
empty string to delete that key. Setting the reserved "notes" key
updates the transaction's top-level notes field instead.
@spec list(Monzo.Client.t(), list_params()) :: {:ok, [Monzo.Transaction.t()]} | {:error, Exception.t()}
Returns a single page of transactions for an account.
Full-history sync window
Monzo only allows fetching a user's complete transaction history during
the first 5 minutes after authentication. After that window, only the
last 90 days are available. If you need full history, call list/2 or
stream/2 immediately after the OAuth callback completes.
@spec retrieve(Monzo.Client.t(), retrieve_params()) :: {:ok, Monzo.Transaction.t()} | {:error, Exception.t()}
Fetches a single transaction by id, optionally expanding :merchant inline.
{:ok, tx} = Monzo.Transactions.retrieve(client, %{transaction_id: "tx_123", expand: [:merchant]})
@spec stream(Monzo.Client.t(), stream_params()) :: Enumerable.t()
Returns a lazy Stream that walks every transaction for an account,
oldest first, across as many pages as needed - fetching each page only
as the stream is consumed.
client
|> Monzo.Transactions.stream(%{account_id: account_id})
|> Enum.each(fn tx -> IO.puts("#{tx.created} #{tx.amount} #{tx.description}") end)
# Or lazily take just the first 10:
first_ten = client |> Monzo.Transactions.stream(%{account_id: account_id}) |> Enum.take(10)