pymonzo version: v0.11.0
(latest)
This started happening for me since 15.03.2022:
Stacktrace:
...
File "/app/export.py", line 44, in <genexpr>
self.api.transaction(t['id'], expand_merchant=True)._raw_data
File "/usr/local/lib/python3.8/site-packages/pymonzo/monzo_api.py", line 398, in transaction
return MonzoTransaction(data=response.json()['transaction'])
File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 42, in __init__
self._parse_special_fields(data_copy)
File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 117, in _parse_special_fields
self.merchant = MonzoMerchant(data=data.pop('merchant'))
File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 33, in __init__
raise ValueError(
ValueError: Passed data doesn't have all required keys (missing keys: created)
More debugging:
DEBUG:requests_oauthlib.oauth2_session:Passing through key word arguments {'params': {'expand[]': 'merchant'}, 'allow_redirects': True}.
DEBUG:urllib3.connectionpool:https://api.monzo.com:443 "GET /transactions/tx_XXXXXXXXXXXXXXX?expand%5B%5D=merchant HTTP/1.1" 200 None
(Pdb) self.api._get_response(method='get', endpoint=f"/transactions/{transactions[0]['id']}", params={'expand[]': 'merchant'}).json()['transaction']['merchant']
{'id': 'merch_0000A7F9qhxKe3RynPV14E', 'group_id': 'grp_000092JZy7UcN7FpKMkvh3', 'name': 'Deliveroo', 'logo': 'https://mondo-logo-cache.appspot.com/twitter/deliveroo/?size=large', 'emoji': '๐๐ฆ', 'category': 'eating_out', 'online': True, 'atm': False, 'address': {'short_formatted': 'Somewhere in the United Kingdom', 'city': '', 'latitude': 54.557817, 'longitude': -3.484688, 'zoom_level': 4, 'approximate': True, 'formatted': 'United Kingdom', 'address': '', 'region': '', 'country': 'GBR', 'postcode': ''}, 'disable_feedback': False, 'suggested_tags': '#groceries #food, #delivery #yum', 'metadata': {'suggested_tags': '#groceries #food, #delivery #yum', 'website': 'www.deliveroo.co.uk'}
So merchant creation date is missing from the payload. I couldn't find API docs for merchants, so not sure if it's just not passed by the API now
Possibly related: monzo/docs#71
I tried monkey patching it with the following snippet:
M_keys = MonzoMerchant._required_keys
if 'created' in M_keys:
M_keys.remove('created')
But sadly this fails with, so seems created
is hardcoded in pymonzo code
File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 117, in _parse_special_fields
self.merchant = MonzoMerchant(data=data.pop('merchant'))
File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 42, in __init__
self._parse_special_fields(data_copy)
File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 136, in _parse_special_fields
self.created = parse_date(data.pop('created'))
KeyError: 'created`
So I think for now, for my monzoexport, I'll just use the raw __get_response
method. But let me know if you're interested in a proper fix, I might come up with some PR. Thanks!