Version 0.9.0 BETA
Hi developers!
Welcome to the bunq C# SDK! 👨💻
We're very happy to introduce yet another unique product: complete banking SDKs! Now you can build even bigger and better apps and integrate them with your bank of the free! 🌈
Before you dive into this brand new SDK, please consider:
- Checking out our new developer’s page https://bunq.com/en/developer 🙌
- Grabbing your production API key from the bunq app or generate a Sandbox API key using Tinker 🗝
- Visiting together.bunq.com where you can share your creations, questions and experience 🎤
Give us your feedback, create pull requests, build your very own bunq apps and most importantly: have fun! 💪
This SDK is in beta. We cannot guarantee constant availability or stability. Thanks to your feedback we will make improvements on it.
The sdk_csharp
is hosted on nuget.
Install-Package Bunq.Sdk
dotnet add package Bunq.Sdk
In order to start making calls with the bunq API, you must first register your API key and device, and create a session. In the SDKs, we group these actions and call it "creating an API context". The context can be created by using the following code snippet:
var apiContext = ApiContext.Create(ApiEnvironmentType.SANDBOX, API_KEY, DEVICE_DESCRIPTION);
apiContext.Save();
Please note: initializing your application is a heavy task and it is recommended to do it only once per device.
After saving the context, you can restore it at any time:
var apiContext = ApiContext.Restore(API_CONTEXT_FILE_PATH);
Tip: both saving and restoring the context can be done without any arguments. In this case the context will be saved
to/restored from the bunq.conf
file in the same folder with your executable.
The API context can then be saved with:
The file storing the context details (i.e. bunq.conf
) is a key to your account. Anyone having
access to it is able to perform any Public API actions with your account. Therefore, we recommend
choosing a truly safe place to store it.
There is a class for each endpoint. Each class has functions for each supported action. These
actions can be Create
, Get
, Update
, Delete
and List
.
Sometimes API calls have dependencies, for instance MonetaryAccount
. Making changes to a monetary
account always also needs a reference to a User
. These dependencies are required as arguments when
performing API calls. Take a look at doc.bunq.com for the full
documentation.
Creating objects through the API requires an ApiContext
, a requestMap
and identifiers of all
dependencies (such as User ID required for accessing a Monetary Account). Optionally, custom headers
can be passed to requests.
var apiContext = ApiContext.Restore();
var paymentMap = new Dictionary<string, object>
{
{Payment.FIELD_AMOUNT, new Amount(PAYMENT_AMOUNT, PAYMENT_CURRENCY)},
{
Payment.FIELD_COUNTERPARTY_ALIAS,
new Pointer(COUNTERPARTY_POINTER_TYPE, COUNTERPARTY_EMAIL)
},
{Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION}
};
var paymentId = Payment.Create(apiContext, paymentMap, USER_ITEM_ID,
MONETARY_ACCOUNT_ITEM_ID);
See PaymentSample.cs
Reading objects through the API requires an ApiContext
, identifiers of all dependencies (such as
User ID required for accessing a Monetary Account), and the identifier of the object to read (ID or
UUID) Optionally, custom headers can be passed to requests.
This type of calls always returns a model.
var monetaryAccount = MonetaryAccount.Get(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID);
Updating objects through the API goes the same way as creating objects, except that also the object to update identifier (ID or UUID) is needed.
var requestUpdateMap = new Dictionary<string, object> {{RequestInquiry.FIELD_STATUS, STATUS_REVOKED}};
var requestUpdated = RequestInquiry.Update(apiContext, requestUpdateMap, USER_ITEM_ID,
MONETARY_ACCOUNT_ITEM_ID, requestId);
See RequestSample.cs
Deleting objects through the API requires an ApiContext
, identifiers of all dependencies (such as User ID required for
accessing a Monetary Account), and the identifier of the object to delete (ID or UUID) Optionally, custom headers can be
passed to requests.
CustomerStatementExport.Delete(apiContext, userId, monetaryAccountId, customerStatementId);
See CustomerStatementExportSample.cs
Listing objects through the API requires an ApiContext
and identifiers of all dependencies (such as User ID required
for accessing a Monetary Account). Optionally, custom headers can be passed to requests.
var users = User.List(apiContext);
In order to make the experience of getting into bunq C# SDK smoother, we have bundled it with BunqSdk.Samples
, a
separate project containing sample use cases of the SDK.
To run a sample, please do the following:
-
In your IDE, open the sample you are interested in and adjust the constants, such as
API_KEY
orUSER_ID
, to hold your data. -
In your terminal, go to the directory of
BunqSdk.Samples
:
$ cd /path/to/bunq/sdk/solution/BunqSdk.Samples/
- In the terminal, run:
$ dotnet run <SomethingSample.cs>
Replace <SomethingSample.cs>
with the name of the sample you would like to run.
In order for samples to run, you would need a valid context file (bunq.conf
) to be present in the BunqSdk.Samples
directory. The file can either copied from somewhere else (e.g. tests) or created by running the following command
in your BunqSdk.Samples
directory:
$ dotnet run ApiContextSaveSample.cs
Please do not forget to set the API_KEY
constant in ApiContextSaveSample.cs
to your actual API key before running the
sample!
Information regarding the test cases can be found in the README.md located in test.
The SDK can throw multiple exceptions. For an overview of these exceptions please take a look at EXCEPTIONS.md