Monzo 0.10.0.18

There is a newer version of this package available.
See the version list below for details.
dotnet add package Monzo --version 0.10.0.18                
NuGet\Install-Package Monzo -Version 0.10.0.18                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Monzo" Version="0.10.0.18" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Monzo --version 0.10.0.18                
#r "nuget: Monzo, 0.10.0.18"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Monzo as a Cake Addin
#addin nuget:?package=Monzo&version=0.10.0.18

// Install Monzo as a Cake Tool
#tool nuget:?package=Monzo&version=0.10.0.18                

Monzo.NET

Monzo

NuGet version NuGet downloads Build status License

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

screenshot

Universal Windows

Also the Universal Windows Sample application using Monzo.NET, Rx and MVVM:

https://github.com/rdingwall/MondoUniversalWindowsSample

screenshot

Contributions

Contributions and pull requests are more than welcome! 🎁

Product 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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 is compatible.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 131 3/27/2024
0.12.1 552 4/29/2021
0.12.0 370 2/18/2021
0.11.0.21 581 10/21/2019
0.10.0.18 670 2/3/2019
0.9.0.17 901 6/10/2018
0.8.0.12 918 5/30/2018