The accounts endpoint can be used to:
- Get a list of accounts belonging to a merchant
- View the transaction history of a specific account
Account details
The following code examples show how to get a list of merchant accounts that the current user has access to:
using System.Net.Http.Json;
const string url = "<<SANDBOX_URL>>accounts";
var jwtToken = Environment.GetEnvironmentVariable("NOFRIXION_USER_TOKEN");
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
try
{
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
// response body contains JSON array of merchant accounts
var accounts = await response.Content.ReadFromJsonAsync<List<Account>>();
if (response.IsSuccessStatusCode)
{
if (accounts != null)
{
foreach (var account in accounts)
{
Console.WriteLine(account);
}
}
else
{
Console.WriteLine(($"You do not have any accounts."));
}
}
else
{
// HTTP error codes will return a MoneyMoov API problem object
Console.WriteLine(await response.Content.ReadFromJsonAsync<ApiProblem>());
}
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
// Type definitiions for returned data
// - The "Account" record is a parital list of properties returned by the API.
// - the full list of properites for MerchantAccount can be found at https://api-sandbox.nofrixion.com/swagger/v1/swagger.json
// and the MerchantAccount schema.
record Account(string customerID, string customerName, string name, string displayName, string currency, string balance);
record ApiProblem(string type, string title, int status, string detail);
// This package allows the script to run on node.js, not required for browser use.
const fetch = require('cross-fetch');
// Remember, the JWT access token must be securely store - this example uses an environment variable
const jwtToken = process.env.NOFRIXION_USER_TOKEN;
const url = '<<SANDBOX_URL>>accounts';
const options = { method: 'GET', headers: { Accept: 'application/json', Authorization: 'Bearer ' + jwtToken } };
fetch(url, options)
.then(response => response.json())
// Resoponse JSON is an array of JSON objects with a list of accounts the user has access to
.then(responseJson => {
// displays complete list of account data
console.log(responseJson);
// alternatively extract array of account Ids (useful for source/destination account dialogs)
console.log(responseJson.map(account => account.id))
})
.catch(err => console.error(err));
# The 'requests' library for Python can be used to make calls to the MoneyMoov API in
# popular python frameworks such as Django and Flask.
import requests
import os
# Remember, the JWT access token must be securely stored ('os' module above allows storage in environment variable)
jwtToken = os.environ['NOFRIXION_USER_TOKEN']
baseUrl = "<<SANDBOX_URL>>accounts"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {jwtToken}"
}
response = requests.request("GET", baseUrl, headers=headers)
if response.ok:
# Convert JSON response to Python dict
accountList = response.json()
# example: view keys/values for each account in the list
for account in accountList:
for accountField in account.keys():
print(f"{accountField}: {account[accountField]}")
# Print a blank line between accounts for readability
print()
else:
# If not OK, response contains MoneyMoov problem (https://docs.nofrixion.com/reference/error-messages)
print(response.json())
Note, if the user is authorized for multiple merchants then accounts belonging to the current merchant context will be shown. See User profile and merchant settings for more information.
Transactions History
The account transactions endpoint returns a JSON object containing:
- an array containing the number of transactions specified (default = 20).
- some metadata about the transaction history, including the total number of transactions the number of pages
using System.Net.Http.Json;
const string baseUrl = "<<SANDBOX_URL>>accounts";
var jwtToken = Environment.GetEnvironmentVariable("NOFRIXION_USER_TOKEN");
// Id of account to get transaction history from
string accountID = "A120P0JR";
// by default each call will return 20 transactions, we can change this using a query parameter as shown below.
// a start date or page number can also be requested using query parameters
string queryParams = "?size=10";
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
try
{
var response = await client.GetAsync($"{baseUrl}/{accountID}/transactions{queryParams}");
if (response.IsSuccessStatusCode)
{
// response body contains some transaction page metadata JSON array of transactions
var page = await response.Content.ReadFromJsonAsync<TransactionPage>();
if (page != null)
{
// User some of the page metadata
Console.WriteLine($"Showing page {page.page + 1} of {page.totalPages} ({page.size} of {page.totalSize} transactions)");
// Show the returned transactions
foreach (Transaction trans in page.transactions)
{
Console.WriteLine(trans);
}
}
else
{
Console.WriteLine($"No transactions returned.");
}
}
else
{
// HTTP error codes will return a MoneyMoov API problem object
Console.WriteLine(await response.Content.ReadFromJsonAsync<ApiProblem>());
}
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
// Type definitiions for returned data
// - This endpoint returns a "TransactionPageResponse": some metadata about the page and an array of transactions,
// the length of which is specified by the 'size' query parameter
// - the example here uses a limited set of properties. A full list of properites for returned can be found at
// https://api-sandbox.nofrixion.com/swagger/v1/swagger.json in the TransactionPageResponse schema.
record Transaction(decimal amount, string currency, string description, string id, string transactionDate);
record TransactionPage(List<Transaction> transactions, int page, double pageStartBalance, int size, int totalPages, int totalSize);
record ApiProblem(string type, string title, int status, string detail);
// This package allows the script to run on node.js, not required for browser use.
const fetch = require('cross-fetch');
// Remember, the JWT access token must be securely store - this example uses an environment variable
const jwtToken = process.env.NOFRIXION_USER_TOKEN;
// need to specify the account to get transactions for
var accountId = 'A120P0JR';
// by default each call will return 20 transactions, we can change this using a query parameter as shown below.
var queryParams = '?size=10'
var url = `https://api-sandbox.nofrixion.com/api/v1/accounts/${accountId}/transactions${queryParams}`;
const options = { method: 'GET', headers: { Accept: 'application/json', Authorization: 'Bearer ' + jwtToken } };
fetch(url, options)
.then(response => response.json())
.then(responseJson => {
// the JSON response object contains an array of transactions, oldest first, of the size specified in the query paramater (default=20)
// it also contains properties detailing the current parameter settings, total number of transactions and total number of pages (starting at 0)
console.log(responseJson);
})
.catch(err => console.error(err));
# The 'requests' library for Python can be used to make calls to the MoneyMoov API in
# popular python frameworks such as Django and Flask.
import requests
import os
# Remember, the JWT access token must be securely stored ('os' module above allows storage in environment variable)
jwtToken = os.environ['NOFRIXION_USER_TOKEN']
baseUrl = "<<SANDBOX_URL>>accounts"
# need to specify the account to get transactions for
accountId = "A120P0JR"
# by default each call will return 20 transactions, we can change this using a query parameter as shown below.
queryParams = "?size=10"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {jwtToken}"
}
response = requests.request("GET", f"{baseUrl}/{accountId}/transactions{queryParams}", headers=headers)
if response.ok:
# The response is a JSON object containing
# - transactions: a property that is an array of JSON objects
# - metdata fields: 'page', 'pageStartBalance', 'size', 'totalPages', 'totalSize'
# - these can be used to help with pagination of results (and can be passed in the query string)
data = response.json()
# example: view keys/values for each transaction in the list
# you will notice that the "merchantAccount" property contains further nested objects
for transaction in data['transactions']:
for transactionField in transaction.keys():
print(f"{transactionField}: {transaction[transactionField]}")
# Print a blank line between transactions for readability
print()
# use metadata to summarise displayed transactions
print(f"Showing page {data['page'] + 1} of {data['totalPages'] + 1}. {data['totalSize']} transactions in total.")
else:
# If not OK, response contains MoneyMoov problem (https://docs.nofrixion.com/reference/error-messages)
print(response.json())