bad_request: param is missing or the value is empty: transaction

Just started using the API and it looks beautiful!

Requesting my budgets and accounts works fine, but I'm having trouble adding a transaction.  I'm posting this JSON:

{
  "transaction": {
    "account_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "amount": "12340",
    "cleared": "cleared",
    "date": "2018-04-02",
    "import_id": "YNAB:12340:2018-04-02:1",
    "memo": ""
  }
}

To this URL:

https://api.youneedabudget.com/v1/budgets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/transactions

The reply is: 

{
  "error": {
    "detail": "param is missing or the value is empty: transaction",
    "id": "400",
    "name": "bad_request"
  }
}

What does this error message mean?

8replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Turns out I had to specify the content-type header:

    Content-type: application/json

    The Python requests library doesn't do this by itself, and the header is optional for most websites.  Not sure why YNAB requires it!

    Leaving the answer here for other people who might hit the same problem.

    Like
  • Thanks wessel - I appreciate you coming back to let future users know how you figured it out :) I'll check with the developers as to why that's required. 

    Like
  • wessel I'm glad you figured it out!  Yes, we require Content-Type header to be properly set for PUT/POST requests because this is fairly standard with REST based APIs and also we may accept other formats in the future so we want to be sure the type is unambiguous.

    Like
      • Wessel
      • wessel
      • 2 yrs ago
      • Reported - view

      @Brady Thanks for your reply!  Many API's work well without Content-Type, so if you want to enforce it, why not be explicit about it?  Right now I get a message that says "transaction" is missing. It'd be much clearer to say, "Missing Content-Type header", or "No JSON content found".

      My compliments for the API.  I was pleasantly surprised by the import_id. I ran my tool and it skipped transactions that were imported using the web interface. That was awesome!

      Like
    • wessel Sure thing - there is opportunity to tighten up the clarity on this so I'll put it on our improvement list.  I can't ETA it but I imagine we'll be able to get to this fairly soon.

      Like
      • Roel Spruit
      • Aquamarine_Piranha.3
      • 2 yrs ago
      • Reported - view

      Brady I realise this thread is old but I just wanted to give another +1 for the idea of clarifying this error. I just started working with the API and it took me quite some time (and searching on this forum) to find the reason I couldn't create a transaction.

      Like
    • Roel Spruit and Wessel I'm working on a change that will respond with a helpful error in the situation where you are using POST/PUT and not specifying the Content-Type header.  Hopefully this will improve clarity.

      Like 1
    • FYI - This has been implemented.

      Like
Like Follow
  • Status Answered
  • 2 yrs agoLast active
  • 8Replies
  • 559Views
  • 4 Following