# README
N26 API Client
Unofficial N26 API Client for Golang.
Disclaimer
This project is NOT sponsored or funded by N26 nor any of its competitors.
The client is built on a collection of observed API calls and methods provided by Rots/n26-api.
Prerequisites
Go >= 1.17
Install
go get github.com/nhatthm/n26api
Development
API Service
TBA
API Client
TBD
Testkit
Unit Test
The services can be easily mocked by using the testkit
, all the mocked interface is provided
by stretchr/testify/mock
For example: Mocking transaction.Finder
service
package test
import (
"context"
"testing"
"time"
"github.com/google/uuid"
transactionMock "github.com/nhatthm/n26api/pkg/testkit/transaction"
"github.com/nhatthm/n26api/pkg/transaction"
"github.com/stretchr/testify/assert"
)
func TestTransactions(t *testing.T) {
t.Parallel()
from := time.Now()
to := from.Add(time.Hour)
id := uuid.New()
f := transactionMock.MockFinder(func(f *transactionMock.Finder) {
f.On("FindAllTransactionsInRange", context.Background(), from, to).
Return(
[]transaction.Transaction{
{ID: id, OriginalAmount: 3.5},
},
nil,
)
})(t)
expected := []transaction.Transaction{
{ID: id, OriginalAmount: 3.5},
}
result, err := f.FindAllTransactionsInRange(context.Background(), from, to)
assert.Equal(t, expected, result)
assert.NoError(t, err)
}
Integration Test
The testkit
provides a mocked API server for testing.
For example:
package test
import (
"context"
"testing"
"time"
"github.com/google/uuid"
"github.com/nhatthm/n26api"
"github.com/nhatthm/n26api/pkg/testkit"
"github.com/nhatthm/n26api/pkg/transaction"
)
func TestFindTransactions(t *testing.T) {
t.Parallel()
username := "username"
password := "password"
deviceID := uuid.New()
from := time.Now()
to := from.Add(time.Hour)
pageSize := int64(1)
id1 := uuid.New()
id2 := uuid.New()
s := testkit.MockServer(username, password, deviceID,
testkit.WithFindAllTransactionsInRange(
from, to, pageSize,
[]transaction.Transaction{{ID: id1}, {ID: id2}},
),
)(t)
c := n26api.NewClient(
n26api.WithBaseURL(s.URL()),
n26api.WithDeviceID(deviceID),
n26api.WithCredentials(username, password),
n26api.WithMFAWait(5*time.Millisecond),
n26api.WithMFATimeout(time.Second),
n26api.WithTransactionsPageSize(pageSize),
)
result, err := c.FindAllTransactionsInRange(context.Background(), from, to)
// assertions
}
Server Options
WithFindAllTransactionsInRange
TBD
Test
Unit Test
Run
make test
or
make test-unit
Integration Test
TBD
GDPR
No information is used or store by this module.
References
- https://github.com/guitmz/n26 (for MFA)
- https://github.com/Rots/n26-api (for OpenAPI doc)
Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
Paypal donation
or scan this

# Packages
No description provided by the author
# Functions
BasicAuthRoundTripper sets Basic Authorization header to the given request.
BearerAuthRoundTripper sets Bearer Authorization header to the given request.
Credentials initiates a new credentials provider.
CredentialsFromEnv initiates a new credentials provider.
NewClient initiates a new transaction.Finder.
NewInMemoryTokenStorage initiates a new InMemoryTokenStorage.
TokenRoundTripper sets Bearer Authorization header to the given request with a token given by a auth.TokenProvider.
WithBaseURL sets API Base URL.
WithClock sets the clock (for testing purpose).
WithCredentials sets username and password to login.
WithCredentialsProvider chains a new credentials provider.
WithCredentialsProviderAtLast chains a new credentials provider at last position.
WithDeviceID sets device ID to login.
WithMFATimeout sets the MFA Timeout for authentication.
WithMFAWait sets the MFA Wait Time for authentication.
WithPassword sets password to login.
WithTimeout sets API Timeout.
WithTokenProvider chains a new token provider.
WithTokenStorage sets token storage for the internal apiTokenProvider.
WithTransactionsPageSize sets page size limit for finding transactions.
WithUsername sets username to login.
# Constants
BaseURL is N26 API Base URL.
DefaultPageSize is the default page size while requesting to N26.
# Variables
ErrPasswordIsEmpty indicates that the username is empty.
ErrTokenKeyEmpty indicates that the key of token is empty and we can not persist that.
ErrUsernameIsEmpty indicates that the username is empty.
# Structs
Client provides all N26 APIs.
InMemoryTokenStorage persists auth.OAuthToken into its memory.
# Interfaces
CredentialsProvider provides username and password for authentication.