Documentation ¶
Index ¶
- Constants
- Variables
- func CheckResponse(r *http.Response) (err error)
- func OAuth2Config(clientID, clientSecret, redirectURL string) *oauth2.Config
- func ParseResponse(resp *http.Response, errIn error, v any) (err error)
- func WebhookPayloadHandler(handler func(rw http.ResponseWriter, r *http.Request, payload *WebhookPayload)) http.HandlerFunc
- type Account
- type AccountOwner
- type AccountType
- type AccountsList
- type AccountsService
- type AttachmentsService
- type Balance
- type BalanceService
- type Client
- func (c *Client) Delete(url string) (resp *http.Response, err error)
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) Get(url string, body any) (resp *http.Response, err error)
- func (c *Client) LogOut() (err error)
- func (c *Client) NewRequest(method, url string, body any) (*http.Request, error)
- func (c *Client) NewRequestWithContext(ctx context.Context, method, urlStr string, body any) (req *http.Request, err error)
- func (c *Client) Patch(url string, body any) (resp *http.Response, err error)
- func (c *Client) Post(url string, body any) (resp *http.Response, err error)
- func (c *Client) Put(url string, body any) (resp *http.Response, err error)
- func (c *Client) RefreshToken() (err error)
- func (c *Client) RefreshTokenOnNextRequest() (err error)
- func (c *Client) Token() (*oauth2.Token, error)
- func (c *Client) Whoami() (who *Whoami, err error)
- type Error
- type FeedItem
- type FeedItemParamsBasic
- type FeedService
- type Merchant
- type MerchantAddress
- type Pagination
- type PaymentDetails
- type PaymentDetailsLocaleUK
- type Pot
- type PotsList
- type PotsService
- func (s *PotsService) Deposit(potID, sourceAccountID string, amount int, dedupeID string) (pot *Pot, err error)
- func (s *PotsService) Get(potID string) (pot *Pot, err error)
- func (s *PotsService) List(accountID string) (list *PotsList, err error)
- func (s *PotsService) Withdraw(potID, destinationAccountID string, amount int, dedupeID string) (pot *Pot, err error)
- type ReceiptsService
- type Transaction
- type TransactionList
- type TransactionSingle
- type TransactionsService
- func (s *TransactionsService) Annotate(transactionID string, metadata map[string]string) (tx *TransactionSingle, err error)
- func (s *TransactionsService) Get(transactionID string, expandMerchant bool) (tx *TransactionSingle, err error)
- func (s *TransactionsService) List(accountID string, expandMerchant bool, paging *Pagination) (list *TransactionList, err error)
- type Webhook
- type WebhookList
- type WebhookPayload
- type WebhookSingle
- type WebhooksService
- type Whoami
Constants ¶
const ( // DefaultUserAgent is the user-agent string that will be sent to the server, unless it is overridden on the Client. DefaultUserAgent = "go-monzo/1.0 (https://github.com/arylatt/go-monzo)" // BaseURL is the default Monzo API URL. BaseURL = "https://api.monzo.com" )
const (
// FeedTypeBasic is currently the only supported feed type.
FeedTypeBasic = "basic"
)
Variables ¶
var ( // ErrPotInvalidID is returned if a null/empty Pot ID is supplied. ErrPotInvalidID = errors.New("pot id cannot be empty") // ErrPotInvalidSourceAccountID is returned if a null/empty Source Account ID is supplied. ErrPotInvalidSourceAccountID = errors.New("source account id cannot be empty") // ErrPotInvalidDepositAmount is returned if a zero/negative deposit amount is supplied. ErrPotInvalidDepositAmount = errors.New("deposit amount must be a positive number") // ErrPotInvalidWithdrawAmount is returned if a zero/negative withdrawal amount is supplied. ErrPotInvalidWithdrawAmount = errors.New("withdraw amount must be a positive number") // ErrPotInvalidDedupeID is returned if a null/empty deduplication ID is supplied. ErrPotInvalidDedupeID = errors.New("dedupe id must not be empty") // ErrPotClientNil is returned if Pot object has a nil client configured (e.g. if the Pot object was manually created). ErrPotClientNil = errors.New("pot client is not configured, use pots client instead") )
var ( // ErrWebhookInvalidAccountID is returned if a null/empty Account ID is supplied. ErrWebhookInvalidAccountID = errors.New("account id cannot be empty") // ErrWebhookInvalidURL is returned if a null/empty URL is supplied. ErrWebhookInvalidURL = errors.New("url cannot be empty") // ErrWebhookClientNil is returned if Webhook object has a nil client configured (e.g. if the Webhook object was manually created). ErrWebhookClientNil = errors.New("webhook client is not configured, use webhooks client instead") )
var ( // ErrTransactionClientNil is returned if Transaction object has a nil client configured // (e.g. if the Transaction object was manually created). ErrTransactionClientNil = errors.New("transaction client is not configured, use transactions client instead") )
var OAuth2Endpoint = oauth2.Endpoint{ AuthURL: "https://auth.monzo.com/", TokenURL: "https://api.monzo.com/oauth2/token", AuthStyle: oauth2.AuthStyleInParams, }
OAuth2Endpoint returns the default OAuth2 endpoint for the Monzo API.
Functions ¶
func CheckResponse ¶
func OAuth2Config ¶
OAuth2Config creates an OAuth2 config based on the provided client ID, client secret, and redirect URL.
func ParseResponse ¶
ParseResponse attempts to decode the HTTP response body into the provided structure.
func WebhookPayloadHandler ¶
func WebhookPayloadHandler(handler func(rw http.ResponseWriter, r *http.Request, payload *WebhookPayload)) http.HandlerFunc
WebhookPayloadHandler returns a HTTP HandlerFunc that can be used to receive the payloads that Monzo sends.
If valid, the webhook payload will already be parsed into the payload argument of the handler function.
The request Body will be reset for further manual processing as desired.
Types ¶
type Account ¶
type Account struct { ID string `json:"id"` Description string `json:"description"` Created string `json:"created"` Closed bool `json:"closed"` Type AccountType `json:"type"` CountryCode string `json:"country_code"` Owners []AccountOwner `json:"owners"` AccountNumber string `json:"account_number"` SortCode string `json:"sort_code"` PaymentDetails PaymentDetails `json:"payment_details"` }
Account represents the account data provided by the Monzo API.
type AccountOwner ¶
type AccountOwner struct { UserID string `json:"user_id"` PreferredName string `json:"preferred_name"` PreferredFirstName string `json:"preferred_first_name"` }
AccountOwner represents the inner account owner data provided by the Monzo API.
type AccountType ¶
type AccountType string
const ( // AccountTypeUKRetail is the single owner UK Current Account type. AccountTypeUKRetail AccountType = "uk_retail" // AccountTypeUKRetailJoint is the joint owner UK Current Account type. AccountTypeUKRetailJoint AccountType = "uk_retail_joint" )
type AccountsList ¶
type AccountsList struct {
Accounts []Account `json:"accounts"`
}
AccountsList represents the response from the Monzo API for a list of accounts.
type AccountsService ¶
type AccountsService service
Accounts represent a store of funds, and have a list of transactions.
func (*AccountsService) List ¶
func (s *AccountsService) List(accountType ...AccountType) (list *AccountsList, err error)
Returns a list of accounts owned by the currently authorised user.
To filter by either single or joint current account, add accountType argument. Valid accountTypes are AccountTypeUKRetail, AccountTypeUKRetailJoint.
type AttachmentsService ¶
type AttachmentsService service
Images (eg. receipts) can be attached to transactions by uploading these via the attachment API. Once an attachment is registered against a transaction, the image will be shown in the transaction detail screen within the Monzo app.
There are two options for attaching images to transactions - either Monzo can host the image, or remote images can be displayed.
type Balance ¶
type Balance struct { Balance int64 `json:"balance"` TotalBalance int64 `json:"total_balance"` BalanceIncludingFlexibleSavings int64 `json:"balance_including_flexible_savings"` Currency string `json:"currency"` SpendToday int64 `json:"spend_today"` LocalCurrency string `json:"local_currency"` LocalExchangeRate int64 `json:"local_exchange_rate"` LocalSpend []interface{} `json:"local_spend"` }
Balance represents the balance data provided by the Monzo API.
type Client ¶
type Client struct { BaseURL *url.URL UserAgent string Accounts *AccountsService Balance *BalanceService Pots *PotsService Transactions *TransactionsService Feed *FeedService Attachments *AttachmentsService Receipts *ReceiptsService Webhooks *WebhooksService // contains filtered or unexported fields }
Client is the Monzo API client.
Client contains modifiable fields: BaseURL for changing where requests are sent, and UserAgent for changing the user-agent string sent to the server.
The various API endpoints are accessed through the different Service fields (e.g. Accounts, Balance, Pots, etc...), based on the Monzo API Reference - https://docs.monzo.com/.
func New ¶
New creates a new Monzo API client based on the parent HTTP client.
The parent HTTP client should contain a transport capable of authorizing requests, either via static access token, or OAuth2.
func (*Client) Do ¶
Do sends a request to the server and attempts to parse the response data for a Monzo API error.
func (*Client) LogOut ¶
LogOut revokes the access and refresh token. A new OAuth2Client will need to be created.
func (*Client) NewRequest ¶
NewRequest creates a new HTTP request to be sent to the Monzo API with a background context.
func (*Client) NewRequestWithContext ¶
func (c *Client) NewRequestWithContext(ctx context.Context, method, urlStr string, body any) (req *http.Request, err error)
NewRequestWithContext creates a new HTTP request to be sent to the Monzo API with the provided context.
The request body is encoded and attached to the request, as well as the appropriate user-agent, content type, and accept request headers.
func (*Client) RefreshToken ¶
RefreshToken updates the expiry time on the OAuth2 token to be in the past, and then calls Whoami to force the OAuth2 transport to refresh the token.
func (*Client) RefreshTokenOnNextRequest ¶
RefreshTokenOnNextRequest updates the expiry time on the OAuth2 token to be in the past, so that the next API call will force the OAuth2 transport to refresh the token.
type Error ¶
type FeedItem ¶
type FeedItem struct { AccountID string `json:"account_id"` Type string `json:"type"` Params FeedItemParamsBasic `json:"params"` URL string `json:"url,omitempty"` }
FeedItem represents an item that can be posted to a user's feed.
type FeedItemParamsBasic ¶
type FeedItemParamsBasic struct { Title string `json:"title"` ImageURL string `json:"image_url"` Body string `json:"body,omitempty"` BackgroundColor string `json:"background_color,omitempty"` TitleColor string `json:"title_color,omitempty"` BodyColor string `json:"body_color,omitempty"` }
FeedItemParamsBasic represents the customization for the basic feed item type.
type FeedService ¶
type FeedService service
The Monzo app is organised around the feed – a reverse-chronological stream of events. Transactions are one such feed item, and your application can create its own feed items to surface relevant information to the user.
func (*FeedService) Create ¶
func (s *FeedService) Create(feedItem FeedItem) (err error)
Creates a new feed item on the user's feed. These can be dismissed.
type Merchant ¶
type Merchant struct { ID string `json:"id"` GroupID string `json:"group_id"` Name string `json:"name"` Logo string `json:"logo"` Emoji string `json:"emoji"` Category string `json:"category"` Created string `json:"created"` Online bool `json:"online"` ATM bool `json:"atm"` Address MerchantAddress `json:"address"` DisableFeedback bool `json:"disable_feedback"` SuggestedTags string `json:"suggested_tags"` Metadata map[string]string `json:"metadata"` }
MerchantAddress represents the inner merchant data provided by the Monzo API.
type MerchantAddress ¶
type MerchantAddress struct { ShortFormatted string `json:"short_formatted"` City string `json:"city"` Latitude float64 `json:"latitude"` Longitude float64 `json:"longitude"` ZoomLevel int64 `json:"zoom_level"` Approximate bool `json:"approximate"` Formatted string `json:"formatted"` Address string `json:"address"` Region string `json:"region"` Country string `json:"country"` Postcode string `json:"postcode"` }
MerchantAddress represents the inner merchant address data provided by the Monzo API.
type Pagination ¶
func (Pagination) BeforeTime ¶
func (p Pagination) BeforeTime() time.Time
func (Pagination) SinceTime ¶
func (p Pagination) SinceTime() time.Time
type PaymentDetails ¶
type PaymentDetails struct {
LocaleUK PaymentDetailsLocaleUK `json:"locale_uk"`
}
PaymentDetails represents the inner payment details account data provided by the Monzo API.
type PaymentDetailsLocaleUK ¶
type PaymentDetailsLocaleUK struct { AccountNumber string `json:"account_number"` SortCode string `json:"sort_code"` }
PaymentDetailsLocaleUK represents the inner payment details account data for UK accounts provided by the Monzo API.
type Pot ¶
type Pot struct { ID string `json:"id"` Name string `json:"name"` Style string `json:"style"` Balance int64 `json:"balance"` Currency string `json:"currency"` Type string `json:"type"` ProductID string `json:"product_id"` CurrentAccountID string `json:"current_account_id"` CoverImageURL string `json:"cover_image_url"` ISAWrapper string `json:"isa_wrapper"` RoundUp bool `json:"round_up"` RoundUpMultiplier float64 `json:"round_up_multiplier"` IsTaxPot bool `json:"is_tax_pot"` Created string `json:"created"` Updated string `json:"updated"` Deleted bool `json:"deleted"` Locked bool `json:"locked"` AvailableForBills bool `json:"available_for_bills"` HasVirtualCards bool `json:"has_virtual_cards"` // contains filtered or unexported fields }
Pot represents a pot object provided by the Monzo API.
func (Pot) Deposit ¶
Move money from an account owned by the currently authorised user into one of their pots.
Pot.Deposit is a convenience method. It is the same as calling Pots.Deposit(pot.ID, sourceAccountID, amount, dedupeID).
type PotsList ¶
type PotsList struct {
Pots []Pot `json:"pots"`
}
PotsList represents the response from the Monzo API for a list of pots.
type PotsService ¶
type PotsService service
A pot is a place to keep some money separate from the main spending account.
func (*PotsService) Deposit ¶
func (s *PotsService) Deposit(potID, sourceAccountID string, amount int, dedupeID string) (pot *Pot, err error)
Move money from an account owned by the currently authorised user into one of their pots.
func (*PotsService) Get ¶
func (s *PotsService) Get(potID string) (pot *Pot, err error)
WARNING: Undocumented Monzo API - may be subject to change!
Returns a specific pot owned by the currently authorised user with the given pot ID.
type ReceiptsService ¶
type ReceiptsService service
Receipts are line-item purchase data added to a transaction. They contain all the information about the purchase, including the products you bought, any taxes that were added on, and how you paid. They can also contain extra details about the merchant you spent money at, such as how to contact them, but this may not appear in the app yet.
type Transaction ¶
type Transaction struct { AccountID string `json:"account_id"` Amount int64 `json:"amount"` AmountIsPending bool `json:"amount_is_pending"` ATMFeesDetailed interface{} `json:"atm_fees_detailed"` Attachments interface{} `json:"attachments"` CanAddToTab bool `json:"can_add_to_tab"` CanBeExcludedFromBreakdown bool `json:"can_be_excluded_from_breakdown"` CanBeMadeSubscription bool `json:"can_be_made_subscription"` CanMatchTransactionsInCategorization bool `json:"can_match_transactions_in_categorization"` CanSplitTheBill bool `json:"can_split_the_bill"` Categories map[string]int64 `json:"categories"` Category string `json:"category"` Counterparty interface{} `json:"counterparty"` Created string `json:"created"` Currency string `json:"currency"` DedupeID string `json:"dedupe_id"` Description string `json:"description"` Fees interface{} `json:"fees"` ID string `json:"id"` IncludeInSpending bool `json:"include_in_spending"` International interface{} `json:"international"` IsLoad bool `json:"is_load"` Labels interface{} `json:"labels"` LocalAmount int64 `json:"local_amount"` LocalCurrency string `json:"local_currency"` Merchant Merchant `json:"merchant"` Metadata map[string]string `json:"metadata"` Notes string `json:"notes"` Originator bool `json:"originator"` ParentAccountID string `json:"parent_account_id"` Scheme string `json:"scheme"` Settled string `json:"settled"` Updated string `json:"updated"` UserID string `json:"user_id"` // contains filtered or unexported fields }
Transaction represents a transaction provided by the Monzo API.
func (*Transaction) Annotate ¶
func (t *Transaction) Annotate(metadata map[string]string) (*TransactionSingle, error)
You may store your own key-value annotations against a transaction in its metadata.
Note: the Monzo API does not seem to be respecting these requests.
Transaction.Annotate is a convenience method. It is the same as calling Transactions.Annotate(transaction.ID, metadata).
func (Transaction) CreatedTime ¶
func (t Transaction) CreatedTime() time.Time
CreatedTime converts the RFC3339 string time into a Time object.
func (Transaction) UpdatedTime ¶
func (t Transaction) UpdatedTime() time.Time
UpdatedTime converts the RFC3339 string time into a Time object.
type TransactionList ¶
type TransactionList struct {
Transactions []Transaction `json:"transactions"`
}
TransactionList represents the response from the Monzo API for a list of transactions.
type TransactionSingle ¶
type TransactionSingle struct {
Transaction Transaction `json:"transaction"`
}
TransactionSingle represents the response from the Monzo API for a single transaction.
type TransactionsService ¶
type TransactionsService service
Transactions are movements of funds into or out of an account. Negative transactions represent debits (ie. spending money) and positive transactions represent credits (ie. receiving money).
func (*TransactionsService) Annotate ¶
func (s *TransactionsService) Annotate(transactionID string, metadata map[string]string) (tx *TransactionSingle, err error)
You may store your own key-value annotations against a transaction in its metadata.
Note: the Monzo API does not seem to be respecting these requests.
func (*TransactionsService) Get ¶
func (s *TransactionsService) Get(transactionID string, expandMerchant bool) (tx *TransactionSingle, err error)
Returns an individual transaction, fetched by its id.
func (*TransactionsService) List ¶
func (s *TransactionsService) List(accountID string, expandMerchant bool, paging *Pagination) (list *TransactionList, err error)
Returns a list of transactions on the user's account.
IMPORTANT - Strong Customer Authentication: After a user has authenticated, your client can fetch all of their transactions, and after 5 minutes, it can only sync the last 90 days of transactions. If you need the user’s entire transaction history, you should consider fetching and storing it right after authentication.
Transactions within the last 90 days can be accessed using the paging argument.
type Webhook ¶
type Webhook struct { AccountID string `json:"account_id"` ID string `json:"id"` URL string `json:"url"` // contains filtered or unexported fields }
Webhook represents a webhook object provided by the Monzo API.
type WebhookList ¶
type WebhookList struct {
Webhooks []Webhook `json:"webhooks"`
}
WebhookList represents the response from the Monzo API for a list of webhooks.
type WebhookPayload ¶
type WebhookPayload struct { Type string `json:"type"` Data Transaction `json:"data"` }
WebhookPayload represents the data that Monzo will send to registered webhook URLs.
type WebhookSingle ¶
type WebhookSingle struct {
Webhook Webhook `json:"webhook"`
}
WebhookSingle represents the response from the Monzo API for a single webhook.
type WebhooksService ¶
type WebhooksService service
Webhooks allow your application to receive real-time, push notification of events in an account.
func (*WebhooksService) Delete ¶
func (s *WebhooksService) Delete(webhookID string) (err error)
Delete removes a webhook from the account.
When you delete a webhook, Monzo will no longer send notifications to it.
func (*WebhooksService) List ¶
func (s *WebhooksService) List(accountID string) (w *WebhookList, err error)
List the webhooks your application has registered on an account.
func (*WebhooksService) Register ¶
func (s *WebhooksService) Register(accountID, webhookURL string) (w *WebhookSingle, err error)
Register creates a webhook entry that Monzo will call.
Each time an event occurs, Monzo will make a POST call to the URL provided. If the call fails, Monzo will retry up to a maximum of 5 attempts, with exponential backoff.