# Bank Account Details OCR

{% hint style="info" %}
This Bank account details OCR is currently available only for French bank account documents.
{% endhint %}

Mindee’s Bank account details OCR API uses deep learning to automatically, accurately, and instantaneously parse data from French RIB (Relevés d'identité Bancaire).

It takes the API a few seconds to extract data from your PDFs or photos of bank account details or RIB. The API extracts the following data:

* Account holder's names
* IBAN
* BBAN (Bank code, branch code, number and key)
* Swift

## Set up the API

{% hint style="info" %}
**Create an API key**

To begin using the Mindee V1 OCR API, your first step is to [create your V1 API key](https://docs.mindee.com/v1/get-started/create-api-key).
{% endhint %}

1. You'll need a bank account details document or RIB. You can use the [sample](https://files.readme.io/e7a3804-image.png) provided below.

   <figure><img src="https://126655343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2al1MDqAP9Dg9iDRjkWg%2Fuploads%2Fgit-blob-cfba520ff47f78c9653add87338ad0fed420e7db%2F8b95350-bank_account_details_sample.jpg?alt=media" alt=""><figcaption></figcaption></figure>
2. Access your Bank Account Details API by clicking on the **Bank Account Details** card in the Document Catalog.

   <figure><img src="https://126655343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2al1MDqAP9Dg9iDRjkWg%2Fuploads%2Fgit-blob-82fcf6876e6c7007c48412831cfe950da31121ac%2Fdf77125-image.png?alt=media" alt=""><figcaption></figcaption></figure>
3. From the left navigation, go to [**documentation**](doc:platform-tour#api---documentation) **> API Reference**, to find sample code in popular languages and command line.

   <figure><img src="https://126655343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2al1MDqAP9Dg9iDRjkWg%2Fuploads%2Fgit-blob-6f2851beefd6ceee65942ae79c164b44a0a5e0e7%2F2e4764f-ScreenShot_Tool_-20230619091354.png?alt=media" alt=""><figcaption></figcaption></figure>

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

```python
from mindee import Client, PredictResponse, product

# Init a new client
mindee_client = Client(api_key="my-api-key-here")

# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")

# Load a file from disk and parse it.
# The endpoint name must be specified since it cannot be determined from the class.
result: PredictResponse = mindee_client.parse(product.fr.BankAccountDetailsV2, input_doc)

# Print a summary of the API result
print(result.document)

# Print the document-level summary
# print(result.document.inference.prediction)
```

{% endtab %}

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

```javascript
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

// Init a new client
const mindeeClient = new mindee.v1.Client({ apiKey: "my-api-key-here" });

// Load a file from disk
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");

// Parse the file
const apiResponse = mindeeClient.parse(
  mindee.v1.product.fr.BankAccountDetailsV2,
  inputSource
);

// Handle the response Promise
apiResponse.then((resp) => {
  // print a string summary
  console.log(resp.document.toString());
});
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using Mindee;
using Mindee.Input;
using Mindee.Product.Fr.BankAccountDetails;

string apiKey = "my-api-key-here";
string filePath = "/path/to/the/file.ext";

// Construct a new client
MindeeClient mindeeClient = new MindeeClient(apiKey);

// Load an input source as a path string
// Other input types can be used, as mentioned in the docs
var inputSource = new LocalInputSource(filePath);

// Call the API and parse the input
var response = await mindeeClient
    .ParseAsync<BankAccountDetailsV2>(inputSource);

// Print a summary of all the predictions
System.Console.WriteLine(response.Document.ToString());

// Print only the document-level predictions
// System.Console.WriteLine(response.Document.Inference.Prediction.ToString());
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

use Mindee\Client;
use Mindee\Product\Fr\BankAccountDetails\BankAccountDetailsV2;

// Init a new client
$mindeeClient = new Client("my-api-key-here");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file
$apiResponse = $mindeeClient->parse(BankAccountDetailsV2::class, $inputSource);

echo $apiResponse->document;
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
#
# Install the Ruby client library by running:
# gem install mindee
#

require 'mindee'

# Init a new client
mindee_client = Mindee::Client.new(api_key: 'my-api-key')

# Load a file from disk
input_source = mindee_client.source_from_path('/path/to/the/file.ext')

# Parse the file
result = mindee_client.parse(
  input_source,
  Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV2
)

# Print a full summary of the parsed data in RST format
puts result.document

# Print the document-level parsed data
# puts result.document.inference.prediction
```

{% endtab %}

{% tab title="Java" %}

```java
import com.mindee.MindeeClient;
import com.mindee.input.LocalInputSource;
import com.mindee.parsing.common.PredictResponse;
import com.mindee.product.fr.bankaccountdetails.BankAccountDetailsV2;
import java.io.File;
import java.io.IOException;

public class SimpleMindeeClient {

  public static void main(String[] args) throws IOException {
    String apiKey = "my-api-key-here";
    String filePath = "/path/to/the/file.ext";

    // Init a new client
    MindeeClient mindeeClient = new MindeeClient(apiKey);

    // Load a file from disk
    LocalInputSource inputSource = new LocalInputSource(filePath);

    // Parse the file
    PredictResponse<BankAccountDetailsV2> response = mindeeClient.parse(
        BankAccountDetailsV2.class,
        inputSource
    );

    // Print a summary of the response
    System.out.println(response.toString());

    // Print a summary of the predictions
//  System.out.println(response.getDocument().toString());

    // Print the document-level predictions
//    System.out.println(response.getDocument().getInference().getPrediction().toString());

    // Print the page-level predictions
//    response.getDocument().getInference().getPages().forEach(
//        page -> System.out.println(page.toString())
//    );
  }

}
```

{% endtab %}

{% tab title="Bash" %}

```bash
curl -X POST \\
  https://api.mindee.net/v1/products/mindee/bank_account_details/v2/predict \\
  -H 'Authorization: Token my-api-key-here' \\
  -H 'content-type: multipart/form-data' \\
  -F document=@/path/to/your/file.png
```

{% endtab %}
{% endtabs %}

* Replace **my-api-key-here** with your new API key, or use the **select an API key** feature and it will be filled automatically.
* Copy and paste the sample code of your desired choice in your application, code environment, terminal etc.
* Replace `/path/to/the/file.ext` with the path to your input document.

{% hint style="warning" %}
Remember to replace with your V1 API key.
{% endhint %}

4. Run your code. You will receive a JSON response with the Bank Statement information.

## API Response

Below is the full sample JSON response you get when you call the API. Since the response is quite verbose, we will walk through the fields section by section.

```json
{
  "api_request": {
    "error": {},
    "resources": [
      "document"
    ],
    "status": "success",
    "status_code": 201,
    "url": "https://api.mindee.net/v1/products/mindee/bank_account_details/v2/predict"
  },
  "document": {
    "id": "65383b84-39ce-4aad-8980-3f15589dda5b",
    "name": "bank_account_details_sample.jpg",
    "n_pages": 1,
    "is_rotation_applied": true,
    "inference": {
      "started_at": "2023-06-16T13:22:40.382074",
      "finished_at": "2023-06-16T13:22:41.498981",
      "processing_time": 1.117,
      "pages": [
        {
          "id": 0,
          "orientation": {"value": 0},
          "prediction": { .. },
          "extras": {}
        }
      ],
      "prediction": { .. },
      "extras": {}
    }
  }
}
```

You can find the prediction within the `prediction` key found in two locations:

* **In `document > inference > prediction` for document-level predictions**: it contains the different fields extracted at the document level, meaning that for multi-pages PDFs, we reconstruct a single passport object using all the pages.
* **In `document > inference > pages[ ] > prediction` for page-level predictions**: it gives the prediction for each page independently. With images, there is only one element on this array, but with PDFs, you can find the extracted data for each PDF page.

Each predicted field may contain one or several values:

* a `confidence` score
* a `polygon` highlighting the information location
* a `page_id` where the information was found (document level only)

## Detailed Field Information

Depending on the field type specified, additional attributes can be extracted from the bank account details object. Using the above [RIB example](https://files.readme.io/e7a3804-image.png), the following are the basic fields that can be extracted.

* [Account Holders Names](#account-holders-names)
* [BBAN](#bban)
* [IBAN](#iban)
* [Swift](#swift)

### Account holder name

* **account\_holders\_names**: In the JSON response below, we have the value of the account holder's names outputted as a single string including civilities.

```json
{
   "account_holders_names": {
     "confidence": 0.98,
     "page_id": 0,
     "polygon": [[0.046, 0.841],[0.19, 0.841],[0.19, 0.858],[0.046, 0.858]],
     "value": "MR OLIVIER CESAR"
  }
}
```

### BBAN

* **bban**: In the JSON response below we have the list of values of the bban. For French Bank Account Details only.
  * **bban\_bank\_code**: The bank code outputted as a string.
  * **bban\_branch\_code**: The branch code outputted as a string.
  * **bban\_number**: The bban number outputted as a string.
  * **bban\_key**: The BBAN key outputted as a string

```json
{
  "bban": {
    "bban_bank_code": "12345",
    "bban_branch_code": "12345",
    "bban_key": "16",
    "bban_number": "1234567891A",
    "confidence": 0.56,
    "page_id": 0,
    "polygon": [[0.122, 0.616],[0.44, 0.616],[0.44, 0.754],[0.122, 0.754]]
	}
}
```

### IBAN

* **iban**: In the JSON response below, we have the value of the IBAN.

```json
{
  "iban": {
    "confidence": 0.99,
    "page_id": 0,
    "polygon":  [[0.122, 0.74],[0.384, 0.74],[0.384, 0.754],[0.122, 0.754]],
    "value": "FR8412345123451234567891A16"
  },
}
```

### swift

* **swift**: In the JSON response below, we have the value of the swift code.

```json
{
  "swift": {
      "confidence": 0.95,
      "page_id": 0,
      "polygon":[[0.628, 0.738],[0.809, 0.738],[0.809, 0.754],[0.628, 0.754]],,
      "value": "PSSTFRPPMAR"
  }
}
```
