A Go client for interacting with the Monzo API.
go get -u github.com/tmus/monzo
The client API may change at some point, don't rely on this for anything serious, and make sure you use version numbers in your
go.mod
file.
Create a monzo.Client
and pass it your Monzo access token:
token, _ := os.LookupEnv("MONZO_TOKEN")
c = monzo.NewClient(token)
Creating a new client doesn't verify the connection to Monzo,
so you should call the Ping
method on the new client to ensure
that the client can access Monzo:
if err := c.Ping(); err != nil {
panic(err)
}
Call the Accounts
function on the client to return a slice
of accounts associated with the Monzo token.
accs, _ := c.Accounts()
for _, acc := range accs {
fmt.Println(acc.ID)
}
If you know the account id, you can call the Account
function
on the client to return a single account.
acc, _ := c.Account("acc_00000XXXXXXXXXXXXXXXXX")
fmt.Println(acc.ID)
The Account
struct is fluent: it contains a pointer to the
monzo.Client, meaning further API calls can be done directly
from the Account, such as retrieving a balance:
acc, _ := c.Account("acc_00000XXXXXXXXXXXXXXXXX")
b, _ := acc.Balance()
The Balance
struct contains all the information about an
Account's balance:
Balance.Balance
returns the amount available to spendBalance.Total
returns the total balance (including money
in Pots)Balance.WithSavings
includes the total balance including
money in Savings pots.More details coming soon.