open-banking-pfm-sdk
Version:
The Open Banking PFM SDK uses Client classes and with **Promises** to get responses from the Open Banking PFM API in an easier way and structured as data models.
173 lines (154 loc) • 4.14 kB
Markdown
# Insights Client

Insights and datapoints about user financial information.
## Setup
```javascript
import { InsightsClient } from 'open-banking-pfm-sdk';
//The constructor receives an api key to validate access to all of its functions. This parameter is required. If you want to change the API Server Url you can do it passing it as second parameter.
const SERVER_URL =
'http://tecbantest@ec2-3-21-18-54.us-east-2.compute.amazonaws.com:8081/api/v1/';
const insightsClient = new InsightsClient('XXXX-XXXX-XXXX', SERVER_URL);
```
## How to use
### Resume
Given a valid user ID, fetches a resume of the financial information of a user. It contains expenses, incomes and balances.
```javascript
const insightsOptions = {
accountId:525742481,//Mandatory
dateFrom: number,//Optional
dateTo: number;//Optional
}
insightsClient
.getResume(userId, insightsOptions)
.then((data) => console.log(data))
.catch((error) => console.log(error));
```
Output:
```console
Resume {
_incomes: [],
_expenses: [
IncomeExpense {
_date: 1672552800000,
_categories: [
CategoryResume {
_categoryId: 2,
_amount: 720.82,
_subcategories: [
SubcategoryInsights {
_categoryId: 16,
_amount: 720.82,
_transactionsByDate: [
TransactionsByDate {
_date: 1674194400000,
_transactions: [
Transaction {
_id: 796541939,
_date: 1674194400000,
_charge: true,
_description: 'Clk*Compao Plaza',
_amount: 720.82,
_categoryId: 16,
_dateCreated: 1676572948884,
_lastUpdated: 1676981093696
}
]
}
]
}
]
},
CategoryResume {
_categoryId: 4,
_amount: 433.82,
_subcategories: [ [SubcategoryInsights] ]
},
CategoryResume {
_categoryId: 7,
_amount: 369.82,
_subcategories: [ [SubcategoryInsights] ]
}
],
_amount: 1524.46
},
IncomeExpense {
_date: 1675231200000,
_categories: [Array],
_amount: 12006.02
}
],
_balances: [
Balance { _incomes: 0, _expenses: 12006.02, _date: 1675231200000 },
Balance { _incomes: 0, _expenses: 1524.46, _date: 1672552800000 }
]
}
```
### Analysis
Given a valid user ID, fetches an analysis of the financial information of a user. It contains expenses, incomes and balances.
```javascript
const insightsOptions = {
accountId:525742481,//Mandatory
dateFrom: number,//Optional
dateTo: number;//Optional
}
insightsClient
.getAnalysis(userId, insightsOptions)
.then((data) => console.log(data))
.catch((error) => console.log(error));
```
Output:
```console
[
Analysis {
_date: 1672552800000,
_categories: [
CategoryAnalysis {
_categoryId: 2,
_amount: 720.82,
_subcategories: [
SubcategoryAnalysis {
_categoryId: 16,
_average: 720.82,
_quantity: 1,
_amount: 720.82,
_transactions: [
TransactionAnalysis {
_description: 'Clk*Compao Plaza',
_average: 720.82,
_quantity: 1,
_amount: 720.82
}
]
}
]
},
CategoryAnalysis {
_categoryId: 4,
_amount: 433.82,
_subcategories: [ [SubcategoryAnalysis] ]
},
CategoryAnalysis {
_categoryId: 7,
_amount: 369.82,
_subcategories: [ [SubcategoryAnalysis] ]
}
]
},
Analysis {
_date: 1675231200000,
_categories: [
[CategoryAnalysis],
[CategoryAnalysis],
[CategoryAnalysis],
[CategoryAnalysis],
[CategoryAnalysis],
[CategoryAnalysis],
[CategoryAnalysis]
]
},
Analysis {
_date: 1677650400000,
_categories: [ [CategoryAnalysis] ]
}
]
```