User profile information
The user profile stores the first name, last name and email address for each user, as well as a unique user ID. These details can be returned by calling the user GET action as shown below:
using System.Net.Http.Json;
const string baseUrl = "<<SANDBOX_URL>>user";
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(baseUrl);
if (response.IsSuccessStatusCode)
{
var userProfile = await response.Content.ReadFromJsonAsync<UserProfile>();
// View contents of user profile, can also access as userProfile.firstName etc.
Console.WriteLine(userProfile);
}
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 definitions for returned data
record UserProfile(string firstName, string lastName, string emailAddress);
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_SANDBOX_TOKEN;
const url = '<<SANDBOX_URL>>user';
const options = { method: 'GET', headers: { Accept: 'application/json', Authorization: 'Bearer ' + jwtToken } };
fetch(url, options)
.then(response => response.json())
// Resoponse JSON is a n array of JSON objects with a list of accounts the user has access to
.then(responseJson => {
// Returns JSON object containing logged in User's id, first name, lastname and email address.
console.log(responseJson);
})
.catch(err => console.error(err));
# The 'requests' module 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>>user"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {jwtToken}"
}
response = requests.request("GET", baseUrl, headers=headers)
if response.ok:
# Returns JSON object containing profile...
userProfile = response.json()
print(userProfile)
else:
# If not OK, response contains MoneyMoov problem (https://docs.nofrixion.com/reference/error-messages)
print(response.json())
User merchant settings
Users may be authorised to request and send payments for multiple merchants. The current merchant context for the authenticated user is stored in the user settings and can be used to determine which merchant's data is processed when using other API calls.
User settings can be read using the user/settings GET action as shown below:
using System.Net.Http.Json;
const string baseUrl = "<<SANDBOX_URL>>user/settings";
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(baseUrl);
if (response.IsSuccessStatusCode)
{
var userSettings = await response.Content.ReadFromJsonAsync<List<UserSetting>>();
if (userSettings != null)
{
// As of MoneyMoov v1.1.9 there is only one user setting (CurrentMerchantID), but more may be added in the future
foreach (UserSetting setting in userSettings)
{
Console.WriteLine($"Name: {setting.name}");
Console.WriteLine($"Value: {setting.value}");
Console.WriteLine($"Description: {setting.description}");
}
}
else
{
Console.WriteLine("No user settings 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 definition for returned data
record UserSetting(string name, string value, string description);
record ApiProblem(string type, string title, int status, string detail);
// Gets a user setting for the authenticated user.
// 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_SANDBOX_TOKEN;
const url = '<<SANDBOX_URL>>settings';
const options = { method: 'GET', headers: { Accept: 'text/plain', Authorization: 'Bearer ' + jwtToken } };
fetch(url, options)
.then(response => response.json())
.then(responseJson => {
// Returns JSON object containing the name, value and description of the user setting.
console.log(responseJson);
})
.catch(err => console.error(err));
# The 'requests' module 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>>user/settings"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {jwtToken}"
}
response = requests.request("GET", baseUrl, headers=headers)
if response.ok:
# Returns JSON object containing user settings (currently, the current merchant ID).
userSettings = response.json()
print(userSettings)
else:
# If not OK, response contains MoneyMoov problem (https://docs.nofrixion.com/reference/error-messages)
print(response.json())
The current merchant can be updated using the user/settings POST action:
using System.Net.Http.Json;
using System.Text;
const string baseUrl = "<<SANDBOX_URL>>";
var jwtToken = Environment.GetEnvironmentVariable("NOFRIXION_USER_TOKEN");
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");
string settingName = "CurrentMerchantID";
string settingValue = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
var data = new StringContent($"userSettings[0].Name={settingName}&userSettings[0].Value={settingValue}&userSettings[0].Description=desc",
Encoding.UTF8, "application/x-www-form-urlencoded");
try
{
var response = await client.PostAsync(baseUrl, data);
if (response.IsSuccessStatusCode)
{
// Status "OK" on success
Console.WriteLine(response.StatusCode);
}
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 definition for returned data
record ApiProblem(string type, string title, int status, string detail);
// These modules allow the code to run on Node.js, they aren't required if running in a browser.
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_SANDBOX_TOKEN;
const url = "<<SANDBOX_URL>>user/settings";
var settingName = "CurrentMerchantID";
var settingValue = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
data = `userSettings[0].Name=${settingName}&userSettings[0].Value=${settingValue}f&userSettings[0].Description=desc`;
const options = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Bearer " + jwtToken
},
body: data
};
fetch(url, options)
// status 200 on success
.then(response => console.log(response.status))
.catch(err => console.error(err));
# The 'requests' module 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>>user/settings"
headers = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"Bearer {jwtToken}"
}
settingName = "CurrentMerchantID"
settingValue = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
postData = f"userSettings[0].Name={settingName}&userSettings[0].Value={settingValue}"
response = requests.request("POST", baseUrl, headers=headers, data=postData)
if response.ok:
# HTTP status code 200 on success
print(response.status_code)
else:
# If not OK, response contains MoneyMoov problem (https://docs.nofrixion.com/reference/error-messages)
print(response.json())
The merchants GET endpoint can be used to get a list of merchants the current user is authorised for:
using System.Net.Http.Json;
const string baseUrl = "<<SANDBOX_URL>>merchants";
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(baseUrl);
if (response.IsSuccessStatusCode)
{
var userMerchants = await response.Content.ReadFromJsonAsync<UserMerchants>();
if (userMerchants != null)
{
// View all merchants associated with the authenticated user
foreach (Merchant merchant in userMerchants.merchants)
{
Console.WriteLine(merchant);
}
}
else
{
Console.WriteLine("User is not associated with any merchants.");
}
}
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 definitions for returned data
record Merchant(string id, string name, bool enabled, string modulrMerchantID, string merchantCategoryCode);
record UserMerchants(string CurrentMerchantName, string currentMerchantId, List<Merchant> merchants);
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>>merchants';
const options = { method: 'GET', headers: { Accept: 'application/json', Authorization: 'Bearer ' + jwtToken } };
fetch(url, options)
.then(response => response.json())
// Returns JSON objects containing an array of authorised merchants.
.then(responseJson => console.log(responseJson.merchants))
.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>>merchants"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {jwtToken}"
}
response = requests.request("GET", baseUrl, headers=headers)
if response.ok:
# Returned JSON data contains an array of authorised merchants.
data = response.json()
print(data['merchants'])
else:
# If not OK, response contains MoneyMoov problem (https://docs.nofrixion.com/reference/error-messages)
print(response.json())