[Bug]: importTransactions results in timestamp error
Verified issue does not already exist?
- [X] I have searched and found no existing issue
What happened?
Attempting to insert a transaction using the API results in an error.
var api = require('@actual-app/api');
api.init({
serverURL: '',
password: ''
});
api.importTransactions(accountId, [{
account_id: accountId,
date: "2024-08-23",
amount: 1200,
payee: "Kroger"
}])
Node.js: v20.5.1 on WSL2 Client version: v23.8.1 Server version: v23.8.1
What error did you receive?
/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:31964
let latestTimestamp = (0, _actual_app_crdt__WEBPACK_IMPORTED_MODULE_0__.getClock)().timestamp.toString();
^
TypeError: Cannot read properties of undefined (reading 'timestamp')
at undoDisabled (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:31964:108)
at _runMutator (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:41044:24)
at run (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:44421:45)
at sequenceState.queue.push.resolve.resolve (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:44433:36)
at new Promise (<anonymous>)
at /home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:44432:32
at /home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:31963:83
at runHandler (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:41028:31)
at Object.send (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:40685:92)
at send (/home/nicholas/app/node_modules/@actual-app/api/dist/methods.js:34:21)
Node.js v20.5.1
Where are you hosting Actual?
Docker
What browsers are you seeing the problem on?
No response
Operating System
Linux
What API version are you using? I just tested against a local instance and also a remote instance. Both worked perfectly fine.
var api = require('@actual-app/api');
const config = {
serverURL: 'http://localhost:5006',
password: 'password',
budgetId: '4e805261-6fdc-4c50-b5f3-fa34876644c8',
accountId: '76d2ed74-c606-41c2-8f5d-f18a6f99cadc',
};
(async () => {
await api.init(config);
await api.downloadBudget(config.budgetId);
await api.importTransactions(config.accountId, [{
date: "2024-08-23",
amount: 1200,
payee_name: "Kroger"
}]);
let budget = await api.getBudgetMonth('2023-08');
console.log(budget);
await api.shutdown();
})();
How can I determine the version? It is the version downloaded via "npm install @actual-app/api".
I attempted your code just now and got an error "Segmentation fault".
Can I also double-check, is the accountId the string after "http://server:port/accounts/" when you navigate to an account?
On Sat, 26 Aug 2023 at 18:39, Matiss Janis Aboltins < @.***> wrote:
What API version are you using? I just tested against a local instance and also a remote instance. Both worked perfectly fine.
var api = @.***/api'); const config = { serverURL: 'http://localhost:5006', password: 'password', budgetId: '4e805261-6fdc-4c50-b5f3-fa34876644c8', accountId: '76d2ed74-c606-41c2-8f5d-f18a6f99cadc',};
(async () => { await api.init(config); await api.downloadBudget(config.budgetId);
await api.importTransactions(config.accountId, [{ date: "2024-08-23", amount: 1200, payee: "Kroger" }]); let budget = await api.getBudgetMonth('2023-08'); console.log(budget); await api.shutdown();})();— Reply to this email directly, view it on GitHub https://github.com/actualbudget/actual/issues/1585#issuecomment-1694229651, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE2HTLHQLGKZ6A7IQH4IMYDXXGY3ZANCNFSM6AAAAAA36FFT7M . You are receiving this because you authored the thread.Message ID: @.***>
The api version is 9.8.0
$ npm -v actual-app/api 9.8.0
On Sat, 26 Aug 2023 at 19:31, Nicholas Manojlovic < @.***> wrote:
How can I determine the version? It is the version downloaded via "npm install @actual-app/api".
I attempted your code just now and got an error "Segmentation fault".
Can I also double-check, is the accountId the string after "http://server:port/accounts/" when you navigate to an account?
On Sat, 26 Aug 2023 at 18:39, Matiss Janis Aboltins < @.***> wrote:
What API version are you using? I just tested against a local instance and also a remote instance. Both worked perfectly fine.
var api = @.***/api'); const config = { serverURL: 'http://localhost:5006', password: 'password', budgetId: '4e805261-6fdc-4c50-b5f3-fa34876644c8', accountId: '76d2ed74-c606-41c2-8f5d-f18a6f99cadc',};
(async () => { await api.init(config); await api.downloadBudget(config.budgetId);
await api.importTransactions(config.accountId, [{ date: "2024-08-23", amount: 1200, payee: "Kroger" }]); let budget = await api.getBudgetMonth('2023-08'); console.log(budget); await api.shutdown();})();— Reply to this email directly, view it on GitHub https://github.com/actualbudget/actual/issues/1585#issuecomment-1694229651, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE2HTLHQLGKZ6A7IQH4IMYDXXGY3ZANCNFSM6AAAAAA36FFT7M . You are receiving this because you authored the thread.Message ID: @.***>
The latest version is 6.2.1 🤔
https://www.npmjs.com/package/@actual-app/api?activeTab=versions
oh sorry, that was my mistake - it was just giving me the version of npm I think.
$ npm list nicholas@ /home/nicholas ├── @actual-app/[email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]
On Sat, 26 Aug 2023 at 19:39, Matiss Janis Aboltins < @.***> wrote:
The latest version is 6.2.1 🤔
@.***/api?activeTab=versions
— Reply to this email directly, view it on GitHub https://github.com/actualbudget/actual/issues/1585#issuecomment-1694243570, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE2HTLFY2A7LBVNAY6Z75DDXXG73XANCNFSM6AAAAAA36FFT7M . You are receiving this because you authored the thread.Message ID: @.***>
The version numbers are masked @niko123456000
The version numbers are masked @niko123456000
sorry! I replied by email, didn't know that was a thing ;)
$ npm list nicholas@ /home/nicholas ├── @actual-app/[email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]
I have the exact same set-up as you and things are working perfectly fine for me. So I'm not really sure what the issue might be..
Maybe try running my code snippet posted above against your server?
If that doesn't work - an export of your budget (with redacted information) would be helpful.
I have created a new budget file and I still get the same issues.
If I keep init and downloadBudget I get a 'segementation fault' on node v20 or 'stack smashing detected' on node v18.
in a last ditch attempt I installed node directly into Windows... (not WSL or Pop_OS): it worked.
On Pop_OS I got an error that sqlite was built using a different package version but couldn't really figure out where that was coming from.. it wasn't in my package-lock.json file.
I'm seeing the same error with api.createAccount(account);
/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:31964
let latestTimestamp = (0, _actual_app_crdt__WEBPACK_IMPORTED_MODULE_0__.getClock)().timestamp.toString();
^
TypeError: Cannot read properties of undefined (reading 'timestamp')
at undoDisabled (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:31964:108)
at _runMutator (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:41044:24)
at run (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44421:45)
at sequenceState.queue.push.resolve.resolve (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44433:36)
at new Promise (<anonymous>)
at /root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44432:32
at /root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:31963:83
at runHandler (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:41028:31)
at Object.send (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:40685:92)
at send (/root/actual/node_modules/@actual-app/api/dist/methods.js:34:21)
Fedora 38 (Docker container) Node v18.17.1
npm list
actual@ /root/actual
└── @actual-app/[email protected]
app.js
let api = require('@actual-app/api');
let data = require('/root/actual/my-data.json');
(async () => {
await api.init({
// Budget data will be cached locally here, in subdirectories for each file.
dataDir: '/tmp',
// This is the URL of your running server
serverURL: 'https://example.com',
// This is the password you use to log into the server
password: 'xxxxxxxxxxx'
});
// async function run() {
for (let account of data.accounts) {
console.log("account", account);
let acctId = await api.createAccount(account);
console.log("account id", acctId);
/*
await api.addTransactions(
acctId,
data.transactions
.filter(t => t.acctId === acctId)
.map(convertTransaction),
);
*/
}
// }
// await api.runImport('My-Budget', run);
await api.shutdown();
})();
I had the same issues all described here and the only thing that fixed it was downgrading to node v18.18.2 using nvm
I'm having this same issue while initializing the API in actual-simplefin-sync - the db sync _fullSync function calls getClock - but this call is too early because setClock has not been called yet.
I wonder if previous "cannot reproduce" attempts in this thread started with an empty dataDir folder?
I'm running node version v18.14.2 on windows/bash
This may not be an issue anymore - actual-simplefin-sync was using version 6.2.1 of the API. Updating this to the latest (6.3.0) and this is not reproducible
I'm reproducing this issue with the following minimal code:
const api = require("@actual-app/api");
(async () => {
await api.init({
// This is the URL of your running server
serverURL: 'http://localhost:5006',
// This is the password you use to log into the server
password: 'hunter2',
});
await api.shutdown();
})();
Error:
TypeError: Cannot read properties of undefined (reading 'timestamp')
at _fullSync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42591:98)
at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42503:38
at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:43449:38
at handlers.sync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:38679:73)
at runHandler (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:39555:33)
at Object.send (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:39237:94)
at Object.shutdown (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\index.js:59:25)
at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\minimal.js:10:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[Exception] TypeError: Cannot read properties of undefined (reading 'timestamp')
at _fullSync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42591:98)
at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42503:38
at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:43449:38
at handlers.sync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle
e.api.js:38679:73)
at runHandler (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.ap
pi.js:39555:33)
at Object.send (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.a
api.js:39237:94)
at Object.shutdown (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\index.js
s:59:25)
at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\minimal.js:10:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Process finished with exit code 0
Both with Node 18.20.3 and Node 20.15.0. Actual API version 6.8.2
Turns out you need to always run api.downloadBudget in between. That fixed the problem for me.