Monzo.Transactions (monzo_client v1.0.0)

Copy Markdown View Source

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

annotate_params()

@type annotate_params() :: %{
  transaction_id: String.t(),
  metadata: %{optional(String.t()) => String.t()}
}

expand_field()

@type expand_field() :: :merchant

list_params()

@type list_params() :: %{
  :account_id => String.t(),
  optional(:since) => String.t(),
  optional(:before) => String.t(),
  optional(:limit) => pos_integer(),
  optional(:expand) => [expand_field()]
}

retrieve_params()

@type retrieve_params() :: %{
  :transaction_id => String.t(),
  optional(:expand) => [expand_field()]
}

stream_params()

@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

annotate(client, arg2)

@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.

list(client, params)

@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.

retrieve(client, params)

@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]})

stream(client, params)

@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)