Basic Auth is easy to use as it is simply a username and password that you send along with your api request. It is considered to be less secure for production systems to use but can serve as an easy and fast way to familiarize yourself with the API. Read more about basic auth here
Token authentication is more secure and strongly recommended for production systems. Token authentication works by posting a username and password to a separate endpoint. This endpoint will return a token that you can store securely and use to access the Enin API. Read more about token auth here
Basic authentication is available for quick integration, but discouraged in favor of token authentication.
Use your basic auth id + secret.
mybank-client
Ab3124586Jpwkqnqwpiqjwrqwlqwwmamsadojqwpomqawåqpwkraqokwrpaqo
curl -u "username:password" https://api.enin.ai/analysis/v1/auth-status
NOTE: Powershell does not support curl with basic auth username:password, you will need to convert the username:password hash first.
import requests
from requests.auth import HTTPBasicAuth
# Define the URL and credentials
url = 'https://api.enin.ai/analysis/v1/auth-status'
username = 'username'
password = 'password'
# Make the request with Basic Authentication
response = requests.get(url, auth=HTTPBasicAuth(username, password))
# Print the response text
print(response.text)
response.text should say "You are authenticated".
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
public class BasicAuthRequest {
public static void main(String[] args) {
try {
String url = "https://api.enin.ai/analysis/v1/auth-status";
String username = "username";
String password = "password";
URL urlObj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
String auth = username + ":" + password;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
String authHeaderValue = "Basic " + encodedAuth;
connection.setRequestProperty("Authorization", authHeaderValue);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
System.out.println(content.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Your terminal should print out "You are authenticated".
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var url = "https://api.enin.ai/analysis/v1/auth-status";
var username = "username";
var password = "password";
var byteArray = System.Text.Encoding.ASCII.GetBytes($"{username}:{password}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
var response = await client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
Your console should print "You are authenticated".
Requires axios, run npm install axios
const axios = require('axios');
// API URL
const url = 'https://api.enin.ai/analysis/v1/auth-status';
const username = 'username';
const password = 'password';
// Encode credentials for Basic Auth header
const auth = Buffer.from(`${username}:${password}`).toString('base64');
axios.get(url, {
headers: {
'Authorization': `Basic ${auth}`
}
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});
Your console.log should say "You are authenticated".
This R script uses the httr library to make the GET request: install.packages("httr")
library(httr)
# API URL
url <- "https://api.enin.ai/analysis/v1/auth-status"
# Credentials
username <- "username"
password <- "password"
# Make the request with Basic Authentication
response <- GET(url, authenticate(username, password))
content(response, "text")
You should get the result: "You are authenticated".
Token authentication is recommended for production applications. It works by passing
your YOUR_TOKEN_CLIENT_ID
and YOUR_TOKEN_CLIENT_SECRET
to https://login.enin.ai
using a HTTP POST request. You will get a token as a response
which can be used to access the APIs.
Every token received has an expiration timestamp and is meant to be used until it is expired. Only after expiration should a new one be created. Below we provide an example of how this can be done in python.
NB: you need a seperate token for the Datasets API, and provide the audience as "https://api.enin.ai/datasets"
Every token received has an expiration timestamp and is meant to be used until it is expired. Only after expiration should a new one be created. To further improve on this example you could store the token in a file or in a caching system.
Here is an example of how to fetch company data with token based authentication. You will recieve company data for organization number "917540640" (Enin AS)
Obtain Bearer Token:
curl -X POST "https://login.enin.ai/oauth/token" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "client_credentials",
"client_id": "YOUR_TOKEN_AUTH_ID",
"client_secret": "YOUR_TOKEN_AUTH_SECRET",
"audience": "https://api.enin.ai/analysis"
}'
Fetch and Print Company Data
curl -X GET "https://api.enin.ai/analysis/v1/company/NO917540640" \
-H "Accept: application/json" \
-H "Authorization: Bearer ${ACCESS_TOKEN}"
import requests
import json
from pprint import pprint
def get_api_bearer_token(api_name: str):
# Replace these with your actual credentials
client_id = 'YOUR_TOKEN_AUTH_ID'
client_secret = 'YOUR_TOKEN_AUTH_SECRET'
# Directly fetch a new token
response = requests.post(
"https://login.enin.ai/oauth/token",
headers={"content-type": "application/json"},
json={
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
"audience": f"https://api.enin.ai/{api_name}",
},
)
# Handle basic error response
if response.status_code != 200:
raise Exception("Failed to fetch token.")
token_json = response.json()
return f"{token_json['token_type']} {token_json['access_token']}"
# Fetch and print company data using the API
def fetch_and_print_company_data():
bearer_token = get_api_bearer_token(api_name="analysis")
response = requests.get(
"https://api.enin.ai/analysis/v1/company/NO917540640",
headers = {
"accept": "application/json",
"Authorization": bearer_token,
}
).json()
pprint(response)
# Example usage
fetch_and_print_company_data()
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class Main {
private static final String CLIENT_ID = "YOUR_TOKEN_AUTH_ID";
private static final String CLIENT_SECRET = "YOUR_TOKEN_AUTH_SECRET";
public static void main(String[] args) throws IOException {
String bearerToken = getApiBearerToken("analysis");
fetchAndPrintCompanyData(bearerToken);
}
private static String getApiBearerToken(String apiName) throws IOException {
URL url = new URL("https://login.enin.ai/oauth/token");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
String jsonInputString = String.format("{\"grant_type\": \"client_credentials\", \"client_id\": \"%s\", \"client_secret\": \"%s\", \"audience\": \"https://api.enin.ai/%s\"}", CLIENT_ID, CLIENT_SECRET, apiName);
try(OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
try(Scanner scanner = new Scanner(con.getInputStream())) {
String responseBody = scanner.useDelimiter("\\A").next();
return "Bearer " + responseBody.split("\"access_token\":\"")[1].split("\"")[0];
}
}
private static void fetchAndPrintCompanyData(String bearerToken) throws IOException {
URL url = new URL("https://api.enin.ai/analysis/v1/company/NO917540640");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Authorization", bearerToken);
try(Scanner scanner = new Scanner(con.getInputStream())) {
String responseBody = scanner.useDelimiter("\\A").next();
System.out.println(responseBody);
}
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class Program
{
private static readonly string CLIENT_ID = "YOUR_TOKEN_AUTH_ID";
private static readonly string CLIENT_SECRET = "YOUR_TOKEN_AUTH_SECRET";
public static async Task Main(string[] args)
{
string bearerToken = await GetApiBearerToken("analysis");
await FetchAndPrintCompanyData(bearerToken);
}
private static async Task<string> GetApiBearerToken(string apiName)
{
using (var client = new HttpClient())
{
var requestContent = new StringContent(JsonConvert.SerializeObject(new
{
grant_type = "client_credentials",
client_id = CLIENT_ID,
client_secret = CLIENT_SECRET,
audience = $"https://api.enin.ai/{apiName}"
}), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("https://login.enin.ai/oauth/token", requestContent);
string jsonContent = await response.Content.ReadAsStringAsync();
dynamic tokenData = JsonConvert.DeserializeObject(jsonContent);
return $"Bearer {tokenData.access_token}";
}
}
private static async Task FetchAndPrintCompanyData(string bearerToken)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Authorization", bearerToken);
string response = await client.GetStringAsync("https://api.enin.ai/analysis/v1/company/NO917540640");
Console.WriteLine(response);
}
}
}
const axios = require('axios');
async function getApiBearerToken(apiName) {
const client_id = 'YOUR_TOKEN_AUTH_ID';
const client_secret = 'YOUR_TOKEN_AUTH_SECRET';
const response = await axios.post('https://login.enin.ai/oauth/token', {
grant_type: 'client_credentials',
client_id: client_id,
client_secret: client_secret,
audience: `https://api.enin.ai/${apiName}`,
});
if (response.status !== 200) {
throw new Error('Failed to fetch token.');
}
return `${response.data.token_type} ${response.data.access_token}`;
}
async function fetchAndPrintCompanyData() {
const bearerToken = await getApiBearerToken('analysis');
const response = await axios.get('https://api.enin.ai/analysis/v1/company/NO917540640', {
headers: {
'Accept': 'application/json',
'Authorization': bearerToken,
},
});
console.log(response.data);
}
// Example usage
fetchAndPrintCompanyData();
library(httr)
library(jsonlite)
get_api_bearer_token <- function(api_name) {
client_id <- "YOUR_TOKEN_AUTH_ID"
client_secret <- "YOUR_TOKEN_AUTH_SECRET"
response <- POST("https://login.enin.ai/oauth/token",
body = toJSON(list(grant_type = "client_credentials",
client_id = client_id,
client_secret = client_secret,
audience = paste0("https://api.enin.ai/", api_name))),
content_type_json())
if (status_code(response) != 200) {
stop("Failed to fetch token.")
}
token_data <- content(response)
paste(token_data$token_type, token_data$access_token)
}
fetch_and_print_company_data <- function() {
bearer_token <- get_api_bearer_token("analysis")
response <- GET("https://api.enin.ai/analysis/v1/company/NO917540640",
add_headers(Authorization = bearer_token,
Accept = "application/json"))
data <- content(response, "text")
cat(data)
}
# Example usage
fetch_and_print_company_data()
"Client side error: Missing role(s). Do you have access to {role}? If so have you remembered to add it to
Nk-Role-Keys
in the header?"
Enin requires that you add a special header in order to access data that is protected by a role. This includes: payment remarks, person national identification number, property data, PEP and sanction screening and AML.
Here is an example of how to claim credit check role, and fetch payment remarks with that role.
import requests
from requests.auth import HTTPBasicAuth
# Base URL and endpoint
base_url = "https://api.enin.ai/analysis/v1/" # Assuming Analysis API.
endpoint = "collection-case-composite?debtor_company_identifier=NO917540640"
# Construct full URL
url = f"{base_url}{endpoint}"
username = "MY_BASIC_AUTH_CLIENT_ID"
password = "MY_BASIC_AUTH_SECRET"
# Custom header for role claims
headers = {
"Nk-Role-Keys": "credit_check"
# Ensure these role keys are correct and have been assigned to your API user account
}
response = requests.get(url, auth=HTTPBasicAuth(username, password), headers=headers)
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
public class BasicAuthWithCustomHeader {
public static void main(String[] args) {
try {
String base_url = "https://api.enin.ai/analysis/v1/"; // <- Assumes Analysis API
// Example endpoint:
String endpoint = "collection-case-composite?debtor_company_identifier=NO917540640";
// Construct full URL
String url = base_url + endpoint;
// Basic Auth
String username = "MY_BASIC_AUTH_CLIENT_ID";
String password = "MY_BASIC_AUTH_SECRET";
URL urlObj = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
String auth = username + ":" + password;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
connection.setRequestProperty("Authorization", "Basic " + encodedAuth);
// Custom role claim
connection.setRequestProperty("Nk-Role-Keys", "credit_check");
// Ensure these role keys are correct and have been assigned to your API user account
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
System.out.println(content.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var base_url = "https://api.enin.ai/analysis/v1/";
// Example endpoint:
var endpoint = "collection-case-composite?debtor_company_identifier=NO917540640";
// Construct full URL
var url = $"{base_url}{endpoint}";
var client = new HttpClient();
var username = "MY_BASIC_AUTH_CLIENT_ID";
var password = "MY_BASIC_AUTH_SECRET";
var byteArray = System.Text.Encoding.ASCII.GetBytes($"{username}:{password}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
// Adding custom header for role claims
client.DefaultRequestHeaders.Add("Nk-Role-Keys", "credit_check");
// Ensure these role keys are correct and have been assigned to your API user account
var response = await client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
Requires axios, run npm install axios
const axios = require('axios');
// Base URL
const baseUrl = "https://api.enin.ai/analysis/v1/";
// Example endpoint
const endpoint = "collection-case-composite?debtor_company_identifier=NO917540640";
// Ensure these role keys are correct and have been assigned to your API user account
const roleKeys = "credit_check" // Seperated by comma.
// Construct full URL
const url = `${baseUrl}${endpoint}`;
const username = 'YOUR_BAISC_AUTH_USERNAME';
const password = 'YOUR_BASIC_AUTH_SECRET';
// Encode credentials
const encodedCredentials = Buffer.from(`${username}:${password}`).toString('base64');
// Custom header for role claims
const headers = {
Authorization: `Basic ${encodedCredentials}`, // Alternatively bearer token for token based auth.
'Nk-Role-Keys': roleKeys
};
axios.get(url, { headers })
.then(response => {
console.log(response.data);
console.log("Successfully fetched data with role claims");
})
.catch(error => {
console.error(error);
});
You will need the httr package. If you haven't installed it yet, you can do so by running install.packages("httr") in your R environment.
library(httr)
# Base URL and endpoint
base_url <- "https://api.enin.ai/analysis/v1/"
# Example endpoint:
endpoint <- "collection-case-composite?debtor_company_identifier=NO917540640"
# Construct full URL
url <- paste0(base_url, endpoint)
# Credentials
username <- "MY_BASIC_AUTH_CLIENT_ID"
password <- "MY_BASIC_AUTH_SECRET"
# Custom header for role claims
headers <- c(
`Authorization` = paste("Basic", encodeAuth(username, password)),
`Nk-Role-Keys` = "credit_check"
# Ensure these role keys are correct and have been assigned to your API user account
)
# Make the request
response <- GET(url, add_headers(.headers=headers))
content(response, "text")