-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathynab.py
36 lines (32 loc) · 1.1 KB
/
ynab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from os import getenv
import requests
class YNAB:
def __init__(self):
self.token = getenv('YNAB_TOKEN')
self.endpoint = 'https://api.ynab.com/v1/budgets'
self.headers = {
'Authorization': f'Bearer {self.token}'
}
self.budget_id = self.get_budget_id()
def get_budget_id(self):
response = requests.get(url=self.endpoint,
headers=self.headers)
return response.json()['data']['budgets'][0]['id']
def create_transaction(self):
data = {
'transaction': {
'account_id': None,
'date': None,
'amount': None,
'payee_id': None,
'payee_name': None,
'category_id': None,
'memo': None,
'cleared': None,
'approved': None,
'flag_color': None,
'import_id': None
}
}
response = requests.post(url=f'{self.endpoint}/{self.budget_id}/transactions', headers=self.headers, data=data)
print(response.json())