500 error on POST transaction

I'm having a problem similar to those described here, here and most recently here - but I believe I have already rectified the errors from those posts. I have tried both:

{'transaction': {'account_id': '<acct ID>',
                 'amount': '2000',
                 'approved': True,
                 'category_id': 'null',
                 'cleared': 'cleared',
                 'date': '2021-03-19',
                 'flag_color': 'red',
                 'import_id': 'null',
                 'memo': 'null',
                 'payee_id': 'null',
                 'payee_name': 'null',
                 'subtransactions': []}}

and

{'transaction': {'account_id': '<acct ID>',
                 'amount': '2000',
                 'date': '2021-03-19'}}

but I keep getting the error.

 

I have also tried some other values for the unused fields (empty string, None), but I keep getting a 500 error (or 400 if I muck it up enough). Do more of these fields require actual non-null values? I am at a loss.

3replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Thought I'd try using the bulk syntax instead:

    {'transactions': [{'account_id': '5aa906b2-6a9e-4d05-964f-be38542077a5',
                       'amount': '2000',
                       'date': '2021-03-19'}]}

    yielded

    {'error': {'id': '400', 'name': 'bad_request', 'detail': 'transactions This field is required.'}}

    This seems to confirm the server is to some extent parsing the JSON, because it is not giving this error:

    {'error': {'id': '400', 'name': 'bad_request', 'detail': "either 'transaction' object or 'transactions' array must be supplied"}}

    I still suspect there is something wrong with my JSON encoding, but I don't know what. I am using the Requests python library to convert a python dict to JSON  FWIW.

    Like
  • Hi there Gold Yearling ! If you're using the Python Requests library, try using the "json" parameter to pass that transaction object in rather than the "data" parameter. So something like this should work:

    r = requests.post(url, headers=headers, json={'transaction': {'account_id': '<acct ID>', 'amount': '2000', 'date': '2021-03-19'}})

    To POST a transaction, the only required fields are account_id, amount, and date. All other fields are optional, so if you don't want to supply a value you can just omit those as you did in your second example.

    Like
  • Ha! Yep that fixed it, thanks so much Sarah (YNAB Support)

    Like
Like Follow
  • 4 mths agoLast active
  • 3Replies
  • 55Views
  • 2 Following