# Fetch Banking Data

## HTTPS Request

<mark style="color:green;">`POST`</mark> `https://api.lenmo.app/api/v3/data_marketplace/data_aggregation/fetch_loan_request_data_aggs/`

This endpoint receives loan\_request\_id and returns the data\_aggregation associated with this loan\_request.

#### Headers

| Name                                          | Type   | Description                                                                 |
| --------------------------------------------- | ------ | --------------------------------------------------------------------------- |
| Accept                                        | String | The content type of the response.                                           |
| X-API-KEY<mark style="color:red;">\*</mark>   | String | The API key that gives the user the authentication to perform this request. |
| X-Timestamp<mark style="color:red;">\*</mark> | String | The timestamp of the request.                                               |
| X-HMAC<mark style="color:red;">\*</mark>      | String | The HMAC generated for the request.                                         |

#### Request Body

| Name                                                | Type | Description                                         |
| --------------------------------------------------- | ---- | --------------------------------------------------- |
| loan\_request\_id<mark style="color:red;">\*</mark> | Long | loan request id for the needed aggregation to fetch |

#### Sample Request

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST "https://api.lenmo.app/api/v3/data_marketplace/data_aggregation/fetch_loan_request_data_aggs/" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    -H "X-API-KEY: YOUR_API_KEY" \
    -H "X-Timestamp: REQUEST_TIMESTAMP" \
    -H "X-HMAC: REQUEST_HMAC" \
    -d "{\"loan_request_id\": 1}"
```

{% endtab %}

{% tab title="Python" %}
{% code overflow="wrap" %}

```python
import requests
import json

url = 'https://api.lenmo.app/api/v3/data_marketplace/data_aggregation/fetch_loan_request_data_aggs/'

headers = {
    'Accept': 'application/json',
    'Content-Type: application/json',
    'X-API-KEY': 'YOUR_API_KEY',
    'X-Timestamp': 'REQUEST_TIMESTAMP',
    'X-HMAC': 'REQUEST_HMAC'
}

body = {'loan_request_id': 1}

r = requests.post(url, json=body, headers=headers)

print(r.text)
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}

```java
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static void main(String[] args) {
        try {
            String urlString = "https://api.lenmo.app/api/v3/data_marketplace/data_aggregation/fetch_loan_request_data_aggs/";
            URL url = new URL(urlString);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Accept", "application/json");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("X-API-KEY", "YOUR_API_KEY");
            connection.setRequestProperty("X-Timestamp", "REQUEST_TIMESTAMP");
            connection.setRequestProperty("X-HMAC", "REQUEST_HMAC");
            connection.setDoOutput(true);

            String jsonInputString = "{\"loan_request_id\": 1}";
            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes("utf-8");
                os.write(input, 0, input.length);
            }

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
            String inputLine;
            StringBuilder response = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'
require 'uri'

url = URI("https://api.lenmo.app/api/v3/data_marketplace/data_aggregation/fetch_loan_request_data_aggs/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Content-Type"] = "application/json"
request["X-API-KEY"] = "YOUR_API_KEY"
request["X-Timestamp"] = "REQUEST_TIMESTAMP"
request["X-HMAC"] = "REQUEST_HMAC"
request.body = { loan_request_id: 1 }.to_json

response = http.request(request)
puts response.body

```

{% endtab %}

{% tab title="Node.Js" %}

```javascript
const fetch = require('node-fetch');

const url = 'https://api.lenmo.app/api/v3/data_marketplace/data_aggregation/fetch_loan_request_data_aggs/';

const headers = {
    "Accept": "application/json",
    "Content-Type": "application/json",
    "X-API-KEY": "YOUR_API_KEY",
    "X-Timestamp": "REQUEST_TIMESTAMP",
    "X-HMAC": "REQUEST_HMAC",
};

const body = {
    loan_request_id: 1
};

fetch(url, {
    method: 'POST',
    headers: headers,
    body: JSON.stringify(body)
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$url = "https://api.lenmo.app/api/v3/data_marketplace/data_aggregation/fetch_loan_request_data_aggs/";

$headers = [
    "Accept: application/json",
    "Content-Type: application/json",
    "X-API-KEY: YOUR_API_KEY",
    "X-Timestamp: REQUEST_TIMESTAMP",
    "X-HMAC: REQUEST_HMAC"
];

$body = json_encode([
    "loan_request_id" => 1
]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);
?>

```

{% endtab %}
{% endtabs %}

#### Sample Response

{% tabs %}
{% tab title="200: OK Aggregation is found and successfully fetched" %}

```json
{
  "created": "2022-05-27T10:37:14.658672Z",
  "borrower_bank_name_at_loan_request": "SANDBOX TEST BANK",
  "borrower_bank_balance": "0.00",
  "data_aggregation": {
    "Status": {
      "Severity": "Info",
      "StatusCode": 0,
      "StatusDesc": "Success"
    },
    "DepAcctTrns": {
      "FIAcctId": {
        "AcctId": 6161846,
        "AcctType": "DDA",
        "ExtAcctType": "DDA"
      },
      "BankAcctTrnRec": [
        {
          "Memo": "BOB'S DISCOUNT F DES:PAYROLL ID **003624X INDN:Smith, Jane CO ID:9006",
          "TrnID": 25835773,
          "CurAmt": {
            "Amt": 250.17,
            "CurCode": "USD"
          },
          "TrnType": "Credit",
          "Category": "Earned Income",
          "PostedDt": "2022-05-27",
          "CreatedOnDt": "2022-05-27T11:27:28-07:00",
          "SubCategory": "Wages & Salary"
        },
        {
          "Memo": "BOB'S DISCOUNT F DES:PAYROLL ID **016227X INDN:Smith, Jane CO ID:9006",
          "TrnID": 25835774,
          "CurAmt": {
            "Amt": 359.94,
            "CurCode": "USD"
          },
          "TrnType": "Credit",
          "Category": "Earned Income",
          "PostedDt": "2023-12-12",
          "CreatedOnDt": "2024-06-07T11:27:28-07:00",
          "SubCategory": "Wages & Salary"
        }
      ],
      "SelectionCriterion": {
        "SelRangeDt": {
          "EndDt": "2022-05-27",
          "StartDt": "2021-05-27"
        }
      }
    }
  },
  "agg_90": {
    "avg_credit": 0,
    "avg_debit": 0,
    "credit_30": 0,
    "debit_30": 0,
    "credit_60": 0,
    "debit_60": 0,
    "credit_90": 0,
    "debit_90": 0,
    "total_credit": 0,
    "total_debit": 0,
    "misc_spending_last90": 0,
    "entertainment_spending_last90": 0,
    "lifestyle_spending_last90": 0,
    "education_spending_last90": 0,
    "bank_fees_spending_last90": 0,
    "donations_spending_last90": 0,
    "goods_and_merch_spending_last90": 0,
    "home_expense_spending_last90": 0,
    "services_spending_last90": 0,
    "utilities_spending_last90": 0,
    "credit_payment_spending_last90": 0,
    "transportation_spending_last_90": 0,
    "food_spending_last90": 0,
    "cash_advance_last90": 0,
    "misc_spending_percentage_from_total": 0,
    "entertainment_spending_percentage_from_total": 0,
    "lifestyle_spending_percentage_from_total": 0,
    "education_spending_percentage_from_total": 0,
    "bank_fees_spending_percentage_from_total": 0,
    "donations_spending_percentage_from_total": 0,
    "goods_and_merch_spending_percentage_from_total": 0,
    "home_expense_spending_percentage_from_total": 0,
    "services_spending_percentage_from_total": 0,
    "utilities_spending_percentage_from_total": 0,
    "credit_payment_spending_percentage_from_total": 0,
    "transportation_spending_percentage_from_total": 0,
    "food_spending_percentage_from_total": 0,
    "cash_advance_percentage_from_total": 0,
    "negative_balance_count": 0
  }
}
```

{% endtab %}

{% tab title="400: Bad Request A loan cannot be funded" %}

```javascript
{
    'message': 'Please provide a valid loan_request id'
}
```

{% endtab %}

{% tab title="403: Forbidden Permission Denied" %}

```javascript
{
    "detail": "Authentication credentials were not provided."
}
```

{% endtab %}

{% tab title="404: Not Found Aggregation is not found" %}

```javascript
{
    'message': 'wrong loan_request id or loan_request does not have any data aggs associated with it.'
}
```

{% endtab %}
{% endtabs %}

#### Response Parameters

<table><thead><tr><th width="356">Parameter</th><th width="86">Type</th><th>Description</th></tr></thead><tbody><tr><td>created</td><td>Date</td><td>UTC time of data aggregation saved in the database.</td></tr><tr><td>borrower_bank_name_at_loan_request</td><td>String</td><td>Name of the borrower bank from which aggregation is fetched</td></tr><tr><td>borrower_bank_balance</td><td>String</td><td>Borrower balance in the bank provided the aggregation</td></tr><tr><td>data_aggregation</td><td>JSON</td><td>JSON object containing the data aggregation from the borrower's bank. It contains aggregation data provided by fiserv. Please, refer to <code>DepAcctTrnInqRs</code>entry in fiserv client's response.</td></tr><tr><td>agg_90</td><td>JSON</td><td>A JSON object containing aggregated data from the borrower's bank transactions in the last 90 days <strong>from the date of the loan request creation</strong>.</td></tr><tr><td>avg_credit</td><td>Float</td><td>Average income in the last 90 days.</td></tr><tr><td>avg_debit</td><td>Float</td><td>Average spending in the last 90 days.</td></tr><tr><td>credit_30</td><td>Float</td><td>Total income in the last 30 days.</td></tr><tr><td>debit_30</td><td>Float</td><td>Total spending in the last 30 days.</td></tr><tr><td>credit_60</td><td>Float</td><td>Total income in the last 30-60 days.</td></tr><tr><td>debit_60</td><td>Float</td><td>Total spending in the last 30-60 days.</td></tr><tr><td>credit_90</td><td>Float</td><td>Total income in the last 60-90 days.</td></tr><tr><td>debit_90</td><td>Float</td><td>Total spending in the last 60-90 days.</td></tr><tr><td>total_credit</td><td>Float</td><td>Total income in last 90 days.</td></tr><tr><td>total_debit</td><td>Float</td><td>Total spending in last 90 days.</td></tr><tr><td>misc_spending_last90</td><td>Float</td><td>Total amount spent in the miscellaneous expenses category in the last 90 days.</td></tr><tr><td>entertainment_spending_last90</td><td>Float</td><td>Total amount spent in the entertainment category in the last 90 days.</td></tr><tr><td>lifestyle_spending_last90</td><td>Float</td><td>Total amount spent in the Health &#x26; Lifestyle category in the last 90 days.</td></tr><tr><td>education_spending_last90</td><td>Float</td><td>Total amount spent in the Education category in the last 90 days.</td></tr><tr><td>bank_fees_spending_last90</td><td>Float</td><td>Total amount spent in the Bank Fees &#x26; Charges category in the last 90 days.</td></tr><tr><td>donations_spending_last90</td><td>Float</td><td>Total amount spent in the Donations category in the last 90 days.</td></tr><tr><td>goods_and_merch_spending_last90</td><td>Float</td><td>Total amount spent in the Goods &#x26; Merchandise category in the last 90 days.</td></tr><tr><td>home_expense_spending_last90</td><td>Float</td><td>Total amount spent in the Home Expenses category in the last 90 days.</td></tr><tr><td>services_spending_last90</td><td>Float</td><td>Total amount spent in the Services category in the last 90 days.</td></tr><tr><td>utilities_spending_last90</td><td>Float</td><td>Total amount spent in the Utilities category in the last 90 days.</td></tr><tr><td>credit_payment_spending_last90</td><td>Float</td><td>Total Amount spent in the Transfers &#x26; Adjustments category in the last 90 days.</td></tr><tr><td>transportation_spending_last_90</td><td>Float</td><td>Total Amount spent in the Travel &#x26; Transportation category in the last 90 days.</td></tr><tr><td>food_spending_last90</td><td>Float</td><td>Total Amount spent in the Food &#x26; Dining category in the last 90 days.</td></tr><tr><td>cash_advance_last90</td><td>Float</td><td>Total Amount spent in the Cash Advance subcategory in the last 90 days.</td></tr><tr><td>misc_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Miscellaneous expenses category from the total.</td></tr><tr><td>entertainment_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Entertainment category from the total.</td></tr><tr><td>lifestyle_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Health &#x26; Lifestyle category from the total.</td></tr><tr><td>education_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Education category from the total.</td></tr><tr><td>bank_fees_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Bank Fees &#x26; Charges category from the total.</td></tr><tr><td>donations_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Donations category from the total.</td></tr><tr><td>goods_and_merch_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Goods &#x26; Merchandise category from the total.</td></tr><tr><td>home_expense_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Home Expenses category from the total.</td></tr><tr><td>services_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Services category from the total.</td></tr><tr><td>utilities_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Utilities category from the total.</td></tr><tr><td>credit_payment_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Transfers &#x26; Adjustments category from the total.</td></tr><tr><td>transportation_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Travel &#x26; Transportation category from the total.</td></tr><tr><td>food_spending_percentage_from_total</td><td>Float</td><td>Percentage spent on Food category from the total.</td></tr><tr><td>cash_advance_percentage_from_total</td><td>Float</td><td>Percentage spent on Cash Advance subcategory from the total.</td></tr><tr><td>negative_balance_count</td><td>Integer</td><td>The number of times the borrower's bank balance went negative</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lenme.com/reference/fetch-banking-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
