Skip to content

Commit d7154ae

Browse files
committed
create_transaction Fully omit the import_id from the request body when nil
If `import_id` is present but `nill` in the request payload, the transaction is created with an `import_id` of an empty string. This then causes a 409 response for subsequent transactions. Now fully omitting the property from the request when not present.
1 parent 48296e7 commit d7154ae

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

lib/f2ynab/ynab/client.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ def transactions(since_date: nil, account_id: nil)
2828
end
2929

3030
def create_transaction(id: nil, payee_id: nil, payee_name: nil, amount: nil, cleared: nil, date: nil, memo: nil, flag: nil)
31+
transaction_params = {
32+
account_id: selected_account_id,
33+
date: date.to_s,
34+
amount: amount,
35+
payee_id: payee_id,
36+
payee_name: payee_name,
37+
cleared: cleared ? "Cleared" : 'Uncleared',
38+
memo: memo,
39+
flag_color: flag,
40+
}
41+
transaction_params[:import_id] = id unless id.nil? || id.empty?
42+
3143
client.transactions.create_transaction(
3244
selected_budget_id,
33-
transaction: {
34-
account_id: selected_account_id,
35-
date: date.to_s,
36-
amount: amount,
37-
payee_id: payee_id,
38-
payee_name: payee_name,
39-
cleared: cleared ? "Cleared" : 'Uncleared',
40-
memo: memo,
41-
flag_color: flag,
42-
import_id: id,
43-
},
45+
transaction: transaction_params,
4446
).data.transaction
4547
rescue StandardError => e
4648
Rails.logger.error('YNAB::Client.create_transaction failure')

0 commit comments

Comments
 (0)