Monzo 1.0.0
dotnet add package Monzo --version 1.0.0
NuGet\Install-Package Monzo -Version 1.0.0
<PackageReference Include="Monzo" Version="1.0.0" />
paket add Monzo --version 1.0.0
#r "nuget: Monzo, 1.0.0"
// Install Monzo as a Cake Addin #addin nuget:?package=Monzo&version=1.0.0 // Install Monzo as a Cake Tool #tool nuget:?package=Monzo&version=1.0.0
Monzo.NET
Monzo.NET is a .NET client library for the Monzo bank API. Use it to build apps and view your accounts, balances and transactions, create feed items, manage webhooks and attachments, and more!
>>> Get Monzo.NET via NuGet
Install-Package Monzo
Supported target frameworks: .Net Core, .NET 4.5, ASP.NET Core 5.0, Windows 8, Windows Phone 8.1
Supported Features
- 100% async task-based API
- OAuth 2.0 authentication
- Web application flow (Authorization Code Grant)
- Native CLR types
- Access token refreshing
- Built for unit testing
- List accounts, transactions, and balances
- Create feed items
- Manage webhooks and attachments
- Upload attachments
Usage Examples
Authentication, Accounts, Balances, and Transactions
To authenticate using OAuth 2.0 Web application flow (Authorization Code Grant) and retrieve a list of accounts:
public class HomeController : Controller
{
IMonzoAuthorizationClient _authClient = new MonzoAuthorizationClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET);
[HttpGet]
public ActionResult Login()
{
// an unguessable random string which is used to protect against cross-site request forgery attacks
string state = ...;
// the URL the user should be redirected back to following a successful Monzo login
string redirectUrl = Url.Action("OAuthCallback", "Home", null, Request.Url.Scheme);
string monzoLoginPageUrl = _authClient.GetAuthorizeUrl(state, redirectUrl);
// 1. Send user to Monzo's login page
return Redirect(monzoLoginPageUrl);
}
[HttpGet]
public async Task<ActionResult> OAuthCallback(string code, string state)
{
// confirm the redirect url was valid
string redirectUrl = Url.Action("OAuthCallback", "Home", null, Request.Url.Scheme);
// 2. Exchange authorization code for access token
AccessToken accessToken = await _authClient.GetAccessTokenAsync(code, redirectUrl);
// 3. Begin fetching accounts, transactions etc
using (var client = new MonzoClient(accessToken.Value))
{
IList<Account> accounts = await client.GetAccountsAsync();
// ... etc
}
}
}
Validating your API token
To check if your access token is valid and authenticated:
// List access token info
await client.WhoAmIAsync();
Feed Items
To create a feed item:
// create feed item
var parameters = new Dictionary<string, string>
{
{"title", "My custom item"},
{"image_url", "www.example.com/image.png"},
{"background_color", "#FCF1EE"},
{"body_color", "#FCF1EE"},
{"title_color", "#333"},
{"body", "Some body text to display"},
};
await client.CreateFeedItemAsync("myaccountid", "basic", parameters, "https://www.example.com/a_page_to_open_on_tap.html");
Webhooks
To register, delete and list webhooks:
// list webhooks
IList<Transaction> webhooks = await client.ListTransactionsAsync("myaccountid");
// register new webhook
Webhook webhook = await client.RegisterWebhookAsync("myaccountid", "http://example.com/webhook");
// delete webhook
await client.DeleteWebhookAsync(webhook.Id);
Attachments
To upload, register and remove transaction attachments:
// upload and register an attachment
using (var stream = File.OpenRead(@"C:\example.png"))
{
Attachment attachment = await client.UploadAttachmentAsync("example.png", "image/png", transaction.Id, stream);
}
// register an attachment that is already hosted somewhere
Attachment attachment = await client.RegisterAttachmentAsync(transaction.Id, "http://example.com/pic.png", "image/png");
// remove attachment
await client.DeregisterAttachmentAsync(attachment.Id);
Refreshing your Access Token
OAuth 2.0 access tokens expire and must be periodically refreshed to maintain API access. Here is an example using an Rx IScheduler:
private _refreshDisposable = new SerialDisposable();
// schedule automatic token refresh
private void EnqueueRefresh()
{
DateTimeOffset refreshTime = DateTimeOffset.UtcNow.AddSeconds(_accessToken.ExpiresIn);
_refreshDisposable.Disposable = Scheduler.Default.Schedule(refreshTime, async () =>
{
await _authClient.RefreshAccessTokenAsync(_accessToken.RefreshToken);
EnqueueRefresh();
});
}
Samples
ASP.NET MVC
Check out the ASP.NET MVC Web Application Sample demonstrating OAuth 2.0 Web application flow (Authorization Code Grant):
https://github.com/rdingwall/MondoAspNetMvcSample
Universal Windows
Also the Universal Windows Sample application using Monzo.NET, Rx and MVVM:
https://github.com/rdingwall/MondoUniversalWindowsSample
Contributions
Contributions and pull requests are more than welcome! 🎁
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.