Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Transactions does not take id/import_id as an argument #38

Closed
ntdef opened this issue Jan 20, 2019 · 2 comments
Closed

Update Transactions does not take id/import_id as an argument #38

ntdef opened this issue Jan 20, 2019 · 2 comments

Comments

@ntdef
Copy link

ntdef commented Jan 20, 2019

The docs for update transactions say that the PATCH will update multiple transactions with changes by transaction id or import id.

However, the API doesn't accept id as a field in the transaction change. I get a 400 back when I try to, say, change the flag color on a group of transactions.

For example, the following doesn't work.

require 'date'
require 'ynab'

def update_transactions
  access_token = ENV['YNAB_ACCESS_TOKEN']
  budget_id = ENV['YNAB_BUDGET_ID']
  account_id = ENV['YNAB_ACCOUNT_ID']

  ynab = YNAB::API.new(access_token)

  since_date = Date.parse("2018-11-01")
  target_color = 'purple'

  transactions_response = ynab.transactions.get_transactions_by_account(
    budget_id, account_id, since_date: since_date)

  my_tx = transactions_response.data.transactions

  updated_tx = my_tx.select{ |x| x.flag_color == target_color }.map do |t|
    { id: t.id, flag_color: "red" }
  end
  puts updated_tx
  ynab.transactions.update_transactions(budget_id, { transactions: updated_tx })
  puts "all done"
end

update_transactions
@bradymholt
Copy link
Member

Hello @ntdef 👋!

Thanks for this issue - I am almost certain you are receiving a 400 response because you are not providing complete transaction resources in the transactions array (only sending up { id: t.id, flag_color: "red" }). The PATCH is on the collection, not the resources themselves. So, you are PATCHing, or modifying the collection of transactions but the data for the individual transaction resources must be complete (i.e. have all necessary data).

In #40, I've added an example for update_transactions usage to hopefully make this clearer: https://github.com/ynab/ynab-sdk-ruby/blob/master/examples/update-multiple-transactions.rb

@ntdef
Copy link
Author

ntdef commented Jan 22, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants