plaid/plaid-python

TransactionsSyncResponse has no attribute 'transactions'

bostone opened this issue · 4 comments

The code you advertised in README.md for this project is not working. I'm trying to switch to the preferred (according to you) method and getting plaid.exceptions.ApiAttributeError: TransactionsSyncResponse has no attribute 'transactions' at ['['received_data']']['transactions'] error after getting response and trying to get transactions out of it. The structure you return in response does not contain anything nested or otherwise pertained to transactions. So this call fails:

response = client.transactions_sync(request)
transactions = response['transactions'] # error here

I'm using your latest 10.0.0 release testing on sandbox. Old way works

Perhaps at least modify your example to do transactions = response.get('transactions')?

Hi @bostone, thanks for filing the issue. You're right, there is no 'transactions' field in the response returned by /transactions/sync. I'm going to update the example to reference the 'added' field instead, i.e., transactions = response['added'] (full details of the response body here: https://plaid.com/docs/api/products/transactions/#transactionssync). Thanks and sorry for any confusion this may have caused!

You guys still have bad code example in README.md. Would probably be a good idea to change it. Cheers!

You guys still have bad code example in README.md. Would probably be a good idea to change it. Cheers!

Hi @bostone! We've made the change internally and merged it in. This README is updated when a new version of the client library is published (currently scheduled for early next week!). Here's what the code will look like:

import plaid
from plaid.model.transactions_sync_request import TransactionsSyncRequest

request = TransactionsSyncRequest(
    access_token=access_token,
)
response = client.transactions_sync(request)
transactions = response['added']

# the transactions in the response are paginated, so make multiple calls while incrementing the cursor to
# retrieve all transactions
while (response['has_more']):
    request = TransactionsSyncRequest(
        access_token=access_token,
        cursor=response['next_cursor']
    )
    response = client.transactions_sync(request)
    transactions += response['added']