Hi, I’m new to the Monzo API and trying to pull my transactions from my account to be processed by an app I’m working on. I’ve been able to get an access token which when I authenticate I get a response confirming that ‘authenticated’ is True, however when I try to use the token to get my account and account_id I get a response saying ‘User authentication required’. I’ve noticed that in the Monzo API docs it says that the access token should have user_id included, mine doesn’t so I suspect this might be the/a problem but as the tokens are generated by Monzo I’m not sure how I’d fix that. Or maybe the issue is something else entirely. This is my first post (other than one that I’d worked through by the time it was approved so immediately deleted) so please let me know if I can add anything. Sorry if this seems basic but it’s had me stumped for longer than I’d like to admit. Any help will be much appreciated, thanks! By the way I’m using Flask and running on localhost.
client = OAuth2Session(client_id, client_secret, state=state)
# Get the access token. The fetch token method will automatically check the state in case of CSRF attack
authorization_response = request.url
auth_code_endpoint = "https://api.monzo.com/oauth2/token"
access_token_reponse = client.fetch_token(auth_code_endpoint, authorization_response)
access_token = access_token_reponse['access_token']
# Authenticate the request
authentication_json = requests.get('https://api.monzo.com/ping/whoami', headers={'Authorization': f'Bearer {access_token}'})
authentication_dict = authentication_json.json()
# Get info about accounts, specifically the account ID which is needed to pull the transaction data
accounts_json = requests.get('https://api.monzo.com/accounts', headers={'Authorization': f'Bearer {access_token}'})
accounts_dict = accounts_json.json()
return f"{access_token_reponse}<br><br>{access_token}<br><br>{authentication_dict}<br><br>{accounts_dict}"
{‘authenticated’: True, ‘client_id’: ‘oauth2client_0000A9W9riNXxCki4lZHYf’}
{‘code’: ‘unauthorized.auth_required’, ‘message’: ‘User authentication required’, ‘retryable’: {}}
Somewhat late to the party but I suspect you did not authorise the token in the Monzo App.