Get bank movements

🚧

Warning

This guide is meant to be followed by a backend. Your Secret Key should never be sent to the frontend.

Before we can start using Fintoc, you need to get your Fintoc account's Secret Key. It will be used throughout this guide, so make sure to follow the guide on how to get your API keys to get your live Secret Key.

To get the movements from your bank account, first you need to create a Link and get its Link Token. You can do this from the dashboard, following this guide. Once you have your Link Token, we can start!

📘

Tip

Because we will need to use our Secret Key and a Link Token, some sensitive information needs to be replaced by you to make the code from this guide fully functional. From now on, we will write FINTOC_SECRET_KEY to represent the Secret Key that you need to get and LINK_TOKEN to represent the Link Token required for any of this code to work.

Tooling

This guide shows how to use the Fintoc API using the Python SDK, the Node SDK and cURL.

The cURL tool can be replaced with any tool that allows HTTP requests to be issued through the terminal and shell scripts (for example, Wget).

The SDKs can be installed with the following commands:

pip install fintoc
# Using npm
npm install fintoc

# Using yarn
yarn add fintoc

When using any of the SDKs, please make sure that you're using the latest version. You can find the changelog and versions of the SDKs here (Python SDK) and here (Node SDK).

Getting the correct account

As the guide for creating a Link from the dashboard mentions, a Link represents the username/password combination of the bank. This means that a Link might have more than one account (for example, maybe you have a checking account and a savings account under the same username/password combination). Let's decide which of our accounts has the information that we need!

First, let's list all of our accounts:

from fintoc import Fintoc

fintoc_client = Fintoc("FINTOC_SECRET_KEY")
link = fintoc_client.links.get("LINK_TOKEN")
accounts = link.accounts.all()

for account in accounts:
    print(account.serialize())
import { Fintoc } from 'fintoc';

async function main() {
    const fintocClient = new Fintoc('FINTOC_SECRET_KEY');
    const link = await fintocClient.links.get('LINK_TOKEN');
    const accounts = await link.accounts.all();

    for await (const account of accounts) {
        console.log(account.serialize());
    }
}

main();
curl --request GET \
    --url 'https://api.fintoc.com/v1/accounts/?link_token=LINK_TOKEN' \
    --header 'Authorization: FINTOC_SECRET_KEY'

The output to each of the snippets above should look something like this:

# Prettyfied Output
{
    "balance": {
        "available": 0,
        "current": 0,
        "limit": 0
    },
    "currency": "CLP",
    "holder_id": "199586335",
    "holder_name": "DANIEL ALEJANDRO LEAL BITRAN",
    "id": "acc_MNejK7B76wbJGbl1",
    "name": "Cuenta de Ahorro",
    "number": "340127831",
    "object": "account",
    "official_name": "Cuenta de Ahorro",
    "refreshed_at": "2021-11-30T17:53:59.438000+00:00",
    "type": "savings_account"
}
{
    "balance": {
        "available": 0,
        "current": 0,
        "limit": 200000
    },
    "currency": "CLP",
    "holder_id": "199586335",
    "holder_name": "DANIEL ALEJANDRO LEAL BITRAN",
    "id": "acc_O38ioEA4QejjnGeb",
    "name": "Cuenta Corriente",
    "number": "3945154",
    "object": "account",
    "official_name": "Cuenta Corriente MN",
    "refreshed_at": "2021-11-30T16:54:23.441000+00:00",
    "type": "checking_account"
}
// Prettyfied Output
{
  balance: {
    available: 0,
    current: 0,
    limit: 0
  },
  currency: 'CLP',
  holder_id: '199586335',
  holder_name: 'DANIEL ALEJANDRO LEAL BITRAN',
  id: 'acc_MNejK7B76wbJGbl1',
  name: 'Cuenta de Ahorro',
  number: '340127831',
  object: 'account',
  official_name: 'Cuenta de Ahorro',
  refreshed_at: '2021-11-30T17:53:59.438000+00:00',
  type: 'savings_account'
}
{
  balance: {
    available: 0,
    current: 0,
    limit: 200000
  },
  currency: 'CLP',
  holder_id: '199586335',
  holder_name: 'DANIEL ALEJANDRO LEAL BITRAN',
  id: 'acc_O38ioEA4QejjnGeb',
  name: 'Cuenta Corriente',
  number: '3945154',
  object: 'account',
  official_name: 'Cuenta Corriente MN',
  refreshed_at: '2021-11-30T16:54:23.441000+00:00',
  type: 'checking_account'
}
# Prettyfied Output
[
    {
        "balance": {
            "available": 0,
            "current": 0,
            "limit": 0
        },
        "currency": "CLP",
        "holder_id": "199586335",
        "holder_name": "DANIEL ALEJANDRO LEAL BITRAN",
        "id": "acc_MNejK7B76wbJGbl1",
        "name": "Cuenta de Ahorro",
        "number": "340127831",
        "object": "account",
        "official_name": "Cuenta de Ahorro",
        "refreshed_at": "2021-11-30T17:53:59.438000+00:00",
        "type": "savings_account"
    }
    {
        "balance": {
            "available": 0,
            "current": 0,
            "limit": 200000
        },
        "currency": "CLP",
        "holder_id": "199586335",
        "holder_name": "DANIEL ALEJANDRO LEAL BITRAN",
        "id": "acc_O38ioEA4QejjnGeb",
        "name": "Cuenta Corriente",
        "number": "3945154",
        "object": "account",
        "official_name": "Cuenta Corriente MN",
        "refreshed_at": "2021-11-30T16:54:23.441000+00:00",
        "type": "checking_account"
    }
]

In our case, we want to use the data from our checking account, so we now know that we need to use the account with id acc_O38ioEA4QejjnGeb to search for our movements. The id of your account should be different, but it should also start with acc_.

📘

Tip

From now on, we will write ACCOUNT_ID to represent the id of the account that we want to use.

Getting the movements

Now that we know the id of the account that we want to use, we just need to use it to get the movements!

from fintoc import Fintoc

fintoc_client = Fintoc("FINTOC_SECRET_KEY")
link = fintoc_client.links.get("LINK_TOKEN")
account = link.accounts.get("ACCOUNT_ID")

movements = account.movements.all()

for movement in movements:
    print(movement.serialize())
import { Fintoc } from 'fintoc';

async function main() {
    const fintocClient = new Fintoc('FINTOC_SECRET_KEY');
    const link = await fintocClient.links.get('LINK_TOKEN');
    const account = await link.accounts.get('ACCOUNT_ID');

    const movements = await account.movements.all();

    for await (const movement of movements) {
        console.log(movement.serialize());
    }
}

main();
curl --request GET \
    --url 'https://api.fintoc.com/v1/accounts/ACCOUNT_ID/movements?link_token=LINK_TOKEN' \
    --header 'Authorization: FINTOC_SECRET_KEY' \
    --header 'Accept: application/json'

The output to each of the snippets above should look something like this:

# Prettyfied Output
{
  "id": "mov_J32e7dHabkrqQ48P",
  "description": "Abono por transferencia de Daniel Alejandro Leal Bitrán Rut 19.958.633-5 desde Cuenta Corriente de B.Santander, el 28/11/2021 a las 19:16",
  "amount": 3143097,
  "currency": "CLP",
  "post_date": "2021-11-29T00:00:00.000Z",
  "transaction_date": "2021-11-28T19:16:00.000Z",
  "type": "transfer",
  "recipient_account": None,
  "sender_account": {
    "holder_id": "199586335",
    "number": None,
    "institution": None,
    "holder_name": "Daniel Alejandro Leal Bitran"
  },
  "comment": None,
  "reference_id": None,
  "pending": False,
  "object": "movement"
}
{
  .
  .
  .
}
.
.
.
// Prettyfied Output
{
  id: 'mov_J32e7dHabkrqQ48P',
  description: 'Abono por transferencia de Daniel Alejandro Leal Bitrán Rut 19.958.633-5 desde Cuenta Corriente de B.Santander, el 28/11/2021 a las 19:16',
  amount: 3143097,
  currency: 'CLP',
  post_date: '2021-11-29T00:00:00.000Z',
  transaction_date: '2021-11-28T19:16:00.000Z',
  type: 'transfer',
  recipient_account: null,
  sender_account: {
    holder_id: '199586335',
    number: null,
    institution: null,
    holder_name: 'Daniel Alejandro Leal Bitran'
  },
  comment: null,
  reference_id: null,
  pending: false,
  object: 'movement'
}
{
  .
  .
  .
}
.
.
.
# Prettyfied Output
[
    {
        "id": "mov_J32e7dHabkrqQ48P",
        "description": "Abono por transferencia de Daniel Alejandro Leal Bitrán Rut 19.958.633-5 desde Cuenta Corriente de B.Santander, el 28/11/2021 a las 19:16",
        "amount": 3143097,
        "currency": "CLP",
        "post_date": "2021-11-29T00:00:00.000Z",
        "transaction_date": "2021-11-28T19:16:00.000Z",
        "type": "transfer",
        "recipient_account": null,
        "sender_account": {
            "holder_id": "199586335",
            "number": null,
            "institution": null,
            "holder_name": "Daniel Alejandro Leal Bitran"
        },
        "comment": null,
        "reference_id": null,
        "pending": false,
        "object": "movement"
    },
    {
        .
        .
        .
    },
    .
    .
    .
]

🚧

Warning

Notice that, while every Fintoc SDK handles pagination internally, the cURL method does not automagically paginate the results of the API. Every page returns the last 30 elements of the resource by default. Each response also returns with a Link header that contains the pagination information. To get the next page, look for the next element on the Link header of the response, and make a request to that URL. The pages of a resource end when there is no next element on the Link header of the response.

You can read more about pagination here.