# Fund Loan

## HTTPS Request

<mark style="color:green;">`POST`</mark> `https://api.lenmo.app/api/v3/accepted_offers/{id}/fund/`

We only fund loan using the user's balance now, not balance and bank as done previously. Validation needed for the API endpoint to work:&#x20;

1\. Offer has to be not processed on dwolla before; `processed_on_dwolla` attribute have to be False.

2\. Offer has to be `Accepted`.&#x20;

3\. LoanRequest status has to be `Offered`.&#x20;

4\. Borrower has a primary funding resource.&#x20;

5\. Investor's Balance exceeds the `total_amount` attribute of the Loan.

#### Path Parameters

| Name                                 | Type | Description                         |
| ------------------------------------ | ---- | ----------------------------------- |
| id<mark style="color:red;">\*</mark> | Long | The accepted offer id to be funded. |

#### Headers

| Name                                            | Type   | Description                                                                     |
| ----------------------------------------------- | ------ | ------------------------------------------------------------------------------- |
| Accept                                          | String | The content type of the response.                                               |
| Authorization<mark style="color:red;">\*</mark> | String | The bearer token that give the user the authentication to perform this request. |

{% tabs %}
{% tab title="201: Created A loan is successfully funded" %}

```javascript
{
    'message': 'Loan is started to fund, We will notify you just finish.'
}
```

{% endtab %}

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

```javascript
{
    "detail": // reason for not being able to fund the loan.
}
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

#### Sample Request

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

```bash
curl -X POST "https://api.lenmo.app/api/v3/accepted_offers/125944/fund/" \
    -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"
```

{% endtab %}

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

```python
import requests
import json

offer_id = 126315

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

body = {}

# Fund
url_fund = f'https://api.lenmo.app/api/v3/accepted_offers/{offer_id}/fund/'
response = requests.post(url_fund, json=body, headers=headers)
print(response.json())
```

{% 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 {
            int offerId = 126315;
            String urlString = "https://api.lenmo.app/api/v3/accepted_offers/" + offerId + "/fund/";
            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 = "{}";
            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'

offer_id = 126315
url = URI("https://api.lenmo.app/api/v3/accepted_offers/#{offer_id}/fund/")

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 = {}.to_json

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

```

{% endtab %}

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

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

const offerId = 126315;
const url = `https://api.lenmo.app/api/v3/accepted_offers/${offerId}/fund/`;

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 = {};

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

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$offerId = 126315;
$url = "https://api.lenmo.app/api/v3/accepted_offers/$offerId/fund/";

$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([]);

$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 {
    $json = json_decode($response, true);
    print_r($json);
}

curl_close($ch);
?>

```

{% endtab %}
{% endtabs %}


---

# 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/fund-loan.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.
