actualbudget / import-ynab5

A tool for importing YNAB5 (nYNAB) data into Actual
26 stars 14 forks source link

Can't create payee with transfer_acct #2

Closed aon closed 4 years ago

aon commented 4 years ago

Hey @jlongster ! I'm trying to work on this. I can currently import accounts and categories (tho not sorted yet, for some reason) but the issue I'm having is with payees. I can't seem to set transfer_acct. I don't know if there's maybe something wrong with the API or something wrong with my code:

let api = require('@actual-app/api');
const fs = require('fs') 

async function run() {
  let id = await api.createPayee({
    name: "Test - Tarjeta",
    transfer_acct: "86cf22d5-3ca1-434f-be14-489032bf3fea"
  });
  console.log(await api.getPayees());
}

api.runWithBudget('My-Finances-a8f9d08', run);

And the console logs:

D:\Documentos\GitHub\import-ynab5>node test.js
[
  {
    id: 'cc8010f5-c9f4-47bc-aa9f-cbbc5dd2b50e',
    name: 'cablevision',
    category: null,
    transfer_acct: null
  },
  {
    id: '1b4fb67f-51ea-4408-bf73-7a5243a4bc42',
    name: 'Test - Tarjeta',
    category: null,
    transfer_acct: null
  },
  {
    id: '5b5ef78e-d2ab-40e9-a8c0-2562c33b07b8',
    name: 'Efectivo',
    category: null,
    transfer_acct: '1f9959ad-2725-4dc1-b67f-b800d9a64883'
  },
  {
    id: '041e8dda-8a0e-4d75-975a-98e4080749d6',
    name: 'Tarjeta',
    category: null,
    transfer_acct: '86cf22d5-3ca1-434f-be14-489032bf3fea'
  }
]

Any help would be awesome. Thanks!

jlongster commented 4 years ago

Hey @aon, sorry for the delay!

The docs don't explain this well, but you cannot directly create a transfer payee. Those are considered "internal" and need to be in sync with the list of accounts, otherwise weird things might happen.

When you create an account, a transfer payee is automatically created for that account. So you just need to create the account and that's it. It looks like you've already created that account and the transfer payee already exists:

  {
    id: '041e8dda-8a0e-4d75-975a-98e4080749d6',
    name: 'Tarjeta',
    category: null,
    transfer_acct: '86cf22d5-3ca1-434f-be14-489032bf3fea'
  }
aon commented 4 years ago

Right, that makes sense. I'll have to pull the existing transfer payees and use them for the transactions, something similar to what you did on import-ynab4. Thanks!