belvo.resources.transactions
1from datetime import date 2from typing import Dict, Generator, List, Union 3 4from belvo.resources.base import Resource 5 6 7class Transactions(Resource): 8 endpoint = "/api/transactions/" 9 10 def list(self, link, **kwargs) -> Generator: 11 return super().list(link=link, **kwargs) 12 13 def create( 14 self, 15 link: str, 16 date_from: str, 17 *, 18 date_to: str = None, 19 account: str = None, 20 token: str = None, 21 save_data: bool = True, 22 raise_exception: bool = False, 23 **kwargs: Dict, 24 ) -> Union[List[Dict], Dict]: 25 """Retrieve transactions for a link 26 27 <div style="background-color:#f4f6f8; border-left: 6px solid 28 #0663F9;padding: 12px;margin-left: 25px; border-radius: 4px; margin-right: 29 25px"> <strong>Info: </strong> When retrieving transactions, it is important 30 to understand that the available transaction data ranges depend on each 31 institution. <br><br> 32 33 If you try to access older information than what we can access, we will 34 return all the data we can read within that date range. For example, if you 35 request transactions for the last year and we can only access the last six 36 months, we will return the information corresponding to these six months of 37 data. </div> 38 39 Example: 40 ```python 41 # Fetch transactions for a Link 42 transactions = client.Transactions.create( 43 "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", 44 "2019-07-01", 45 date_to="2019-07-31" 46 ) 47 48 # Fetch transactions for a Link with timeout after 15 seconds 49 transactions = client.Transactions.create( 50 "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", 51 "2019-07-01", 52 date_to="2019-07-31", 53 timeout=15 54 ) 55 56 ``` 57 58 Args: 59 link (str): The `link.id` that you want to get information for (UUID). 60 date_from (str): The date from which you want to start getting transactions for, in `YYYY-MM-DD` format. The value of `date_from` cannot be greater than `date_to`. 61 date_to (str, optional): The date you want to stop getting transactions for, in `YYYY-MM-DD` format. The value of `date_to` cannot be greater than today's date (in other words, no future dates). Defaults to today. 62 account (str, optional): If provided, we return transactions only from this account (UUID). Defaults to None. 63 token (str, optional): The MFA token generated by the bank in order to access the institution. Defaults to None. 64 save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to `True`. 65 raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to `False`. 66 67 Returns: 68 Dict: The details of the object. For more information on the response from the API, see our [Transactions API documentation](https://developers.belvo.com/reference/retrievetransactions). 69 """ 70 71 date_to = date_to or date.today().isoformat() 72 73 data = {"link": link, "date_from": date_from, "date_to": date_to, "save_data": save_data} 74 75 if account: 76 data.update(account=account) 77 if token: 78 data.update(token=token) 79 80 return self.session.post( 81 self.endpoint, data=data, raise_exception=raise_exception, **kwargs 82 )
8class Transactions(Resource): 9 endpoint = "/api/transactions/" 10 11 def list(self, link, **kwargs) -> Generator: 12 return super().list(link=link, **kwargs) 13 14 def create( 15 self, 16 link: str, 17 date_from: str, 18 *, 19 date_to: str = None, 20 account: str = None, 21 token: str = None, 22 save_data: bool = True, 23 raise_exception: bool = False, 24 **kwargs: Dict, 25 ) -> Union[List[Dict], Dict]: 26 """Retrieve transactions for a link 27 28 <div style="background-color:#f4f6f8; border-left: 6px solid 29 #0663F9;padding: 12px;margin-left: 25px; border-radius: 4px; margin-right: 30 25px"> <strong>Info: </strong> When retrieving transactions, it is important 31 to understand that the available transaction data ranges depend on each 32 institution. <br><br> 33 34 If you try to access older information than what we can access, we will 35 return all the data we can read within that date range. For example, if you 36 request transactions for the last year and we can only access the last six 37 months, we will return the information corresponding to these six months of 38 data. </div> 39 40 Example: 41 ```python 42 # Fetch transactions for a Link 43 transactions = client.Transactions.create( 44 "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", 45 "2019-07-01", 46 date_to="2019-07-31" 47 ) 48 49 # Fetch transactions for a Link with timeout after 15 seconds 50 transactions = client.Transactions.create( 51 "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", 52 "2019-07-01", 53 date_to="2019-07-31", 54 timeout=15 55 ) 56 57 ``` 58 59 Args: 60 link (str): The `link.id` that you want to get information for (UUID). 61 date_from (str): The date from which you want to start getting transactions for, in `YYYY-MM-DD` format. The value of `date_from` cannot be greater than `date_to`. 62 date_to (str, optional): The date you want to stop getting transactions for, in `YYYY-MM-DD` format. The value of `date_to` cannot be greater than today's date (in other words, no future dates). Defaults to today. 63 account (str, optional): If provided, we return transactions only from this account (UUID). Defaults to None. 64 token (str, optional): The MFA token generated by the bank in order to access the institution. Defaults to None. 65 save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to `True`. 66 raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to `False`. 67 68 Returns: 69 Dict: The details of the object. For more information on the response from the API, see our [Transactions API documentation](https://developers.belvo.com/reference/retrievetransactions). 70 """ 71 72 date_to = date_to or date.today().isoformat() 73 74 data = {"link": link, "date_from": date_from, "date_to": date_to, "save_data": save_data} 75 76 if account: 77 data.update(account=account) 78 if token: 79 data.update(token=token) 80 81 return self.session.post( 82 self.endpoint, data=data, raise_exception=raise_exception, **kwargs 83 )
def
list(self, link, **kwargs) -> Generator:
List all items for the given resource.
With the .list()
method, you can list all items for a given resource. You can additionally add filters to your method in order to only retrieve results matching your query. If you don't provide any filters, we return all items for that resource.
Example:
# Retrieve all accounts (no filter given)
accounts = client.Accounts.list()
# Retrieve accounts for a specific bank
accounts = client.Accounts.list(institution="erebor_mx_retail")
# Retrieve all checking accounts with an available balance >= 100
accounts = client.Accounts.list(type__in="checking", balance_available__gte=100)
You can find the filters, along with examples, that you can apply per resource by checking our API reference documentation. For example, if you want to see the filters you can apply to the Links resource, then see our List all links documentation.
Returns:
_type_: _description_
Yields:
Generator: _description_
def
create( self, link: str, date_from: str, *, date_to: str = None, account: str = None, token: str = None, save_data: bool = True, raise_exception: bool = False, **kwargs: Dict) -> Union[List[Dict], Dict]:
14 def create( 15 self, 16 link: str, 17 date_from: str, 18 *, 19 date_to: str = None, 20 account: str = None, 21 token: str = None, 22 save_data: bool = True, 23 raise_exception: bool = False, 24 **kwargs: Dict, 25 ) -> Union[List[Dict], Dict]: 26 """Retrieve transactions for a link 27 28 <div style="background-color:#f4f6f8; border-left: 6px solid 29 #0663F9;padding: 12px;margin-left: 25px; border-radius: 4px; margin-right: 30 25px"> <strong>Info: </strong> When retrieving transactions, it is important 31 to understand that the available transaction data ranges depend on each 32 institution. <br><br> 33 34 If you try to access older information than what we can access, we will 35 return all the data we can read within that date range. For example, if you 36 request transactions for the last year and we can only access the last six 37 months, we will return the information corresponding to these six months of 38 data. </div> 39 40 Example: 41 ```python 42 # Fetch transactions for a Link 43 transactions = client.Transactions.create( 44 "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", 45 "2019-07-01", 46 date_to="2019-07-31" 47 ) 48 49 # Fetch transactions for a Link with timeout after 15 seconds 50 transactions = client.Transactions.create( 51 "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", 52 "2019-07-01", 53 date_to="2019-07-31", 54 timeout=15 55 ) 56 57 ``` 58 59 Args: 60 link (str): The `link.id` that you want to get information for (UUID). 61 date_from (str): The date from which you want to start getting transactions for, in `YYYY-MM-DD` format. The value of `date_from` cannot be greater than `date_to`. 62 date_to (str, optional): The date you want to stop getting transactions for, in `YYYY-MM-DD` format. The value of `date_to` cannot be greater than today's date (in other words, no future dates). Defaults to today. 63 account (str, optional): If provided, we return transactions only from this account (UUID). Defaults to None. 64 token (str, optional): The MFA token generated by the bank in order to access the institution. Defaults to None. 65 save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to `True`. 66 raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to `False`. 67 68 Returns: 69 Dict: The details of the object. For more information on the response from the API, see our [Transactions API documentation](https://developers.belvo.com/reference/retrievetransactions). 70 """ 71 72 date_to = date_to or date.today().isoformat() 73 74 data = {"link": link, "date_from": date_from, "date_to": date_to, "save_data": save_data} 75 76 if account: 77 data.update(account=account) 78 if token: 79 data.update(token=token) 80 81 return self.session.post( 82 self.endpoint, data=data, raise_exception=raise_exception, **kwargs 83 )
Retrieve transactions for a link
Info: When retrieving transactions, it is important
to understand that the available transaction data ranges depend on each
institution.
If you try to access older information than what we can access, we will return all the data we can read within that date range. For example, if you request transactions for the last year and we can only access the last six months, we will return the information corresponding to these six months of data.
If you try to access older information than what we can access, we will return all the data we can read within that date range. For example, if you request transactions for the last year and we can only access the last six months, we will return the information corresponding to these six months of data.
Example:
# Fetch transactions for a Link transactions = client.Transactions.create( "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", "2019-07-01", date_to="2019-07-31" ) # Fetch transactions for a Link with timeout after 15 seconds transactions = client.Transactions.create( "b91835f5-6f83-4d9b-a0ad-a5a249f18b7c", "2019-07-01", date_to="2019-07-31", timeout=15 )
Arguments:
- link (str): The
link.id
that you want to get information for (UUID). - date_from (str): The date from which you want to start getting transactions for, in
YYYY-MM-DD
format. The value ofdate_from
cannot be greater thandate_to
. - date_to (str, optional): The date you want to stop getting transactions for, in
YYYY-MM-DD
format. The value ofdate_to
cannot be greater than today's date (in other words, no future dates). Defaults to today. - account (str, optional): If provided, we return transactions only from this account (UUID). Defaults to None.
- token (str, optional): The MFA token generated by the bank in order to access the institution. Defaults to None.
- save_data (bool, optional): Indicates whether or not to persist the data in Belvo. Defaults to
True
. - raise_exception (bool, optional): Indicates whether to raise an exception or return the API error. Defaults to
False
.
Returns:
Dict: The details of the object. For more information on the response from the API, see our Transactions API documentation.